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.
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
}
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With