How to check if char is free in Objective-C?

I need to check if the property is empty or not. It is declared in my header file:

@property (nonatomic) char nextOperation; 

And in the .m file:

 @synthesize nextOperation; 

Correct me if I do something wrong, I'm quite new in this world.

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

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

+4
source share
2 answers

A char cannot be empty. A char is a scalar value, just like an int is only a little less (usually 8 bits). You can compare it with 0 or 0x00 for your purpose.

eg.

 if (!self.nextOperation) { //empty nextOperation } else { //we got something in nextOperation } 
+6
source

Try the following:

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

or simply

 if (!self.nextOperation) { } 

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

+3
source

Source: https://habr.com/ru/post/1437298/


All Articles