Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a char is empty in Objective-C?

I need to test if a property is empty or not. It's declared like this in my header file:

@property (nonatomic) char nextOperation;

And in the .m file:

@synthesize nextOperation;

Correct me if I'm doing anything wrong, I'm pretty new in this world.

In a method I have to test if nextOperation has anything on it. If true (YES?) I should do something, and after that assign a new value to that property.

I've tried nextOperation == '', empty, isEmpty, isempty, and everything throws me an Xcode warning/error.

like image 403
igorsantos07 Avatar asked Jan 16 '23 10:01

igorsantos07


2 Answers

A char can not be empty. A char is a scalar value just like an int - just a little smaller (usually 8 bit). You might want to compare it to 0 or 0x00 for your purpose.

e.g.

if (!self.nextOperation)
{
    //empty nextOperation
}
else
{
    //we got something in nextOperation
}
like image 188
Till Avatar answered Jan 28 '23 17:01

Till


Try this:

if (self.nextOperation == 0) {
    // it's empty
}

or simply

if (!self.nextOperation) {
}

When you declare a property like that (without explicitly declaring an ivar or using @synthesize) you can access the property using the dot syntax (self.property) or use the automatically generated ivar that starts with an underscore (_property).

like image 30
DrummerB Avatar answered Jan 28 '23 18:01

DrummerB