If you cannot get the desired result, I can assure you that this is not because you will get NSCFString instead of NSString .
In Objective-C, a structure is populated with cluster classes; that is, you see the class in the documentation, but in fact it is just an interface. This framework has its own implementations of these classes. For example, as you noted, the NSString class is often represented by the NSCFString class; and there are several others, such as NSConstantString and NSPathStore2 , which are actually subclasses of NSString , and will behave as you expect.
Your problem, from what I see ...
Now sometimes the state can be zero and sometimes filled with text.
... is that in Objective-C it is allowed to call a method on nil . ( nil is the concept of Objective-C null in other languages ββsuch as C # and Java.) However, when you do this, the return value is always nullified; therefore, if the string is nil , any equality comparison made using the method will return NO , even if you compare it to nil . And even then, note that an empty string is not the same as nil , since nil can be thought of as the absence of anything. The empty string has no characters, but hey, at least there. nil doesn't mean anything.
Therefore, instead of using the method to compare state with an empty string, you probably need to check that state not nil using simple pointer equality.
if(state == nil) { //do something } else { //do something }
source share