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.
eg
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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.