Objective-C constants: NSString comparison using ==?

后端 未结 3 1725
时光取名叫无心
时光取名叫无心 2021-01-14 00:03

The discussions I found about setting NSString constants made me code it the following way:

.h file:

extern NSString * const kSectionHeaders;
         


        
3条回答
  •  我在风中等你
    2021-01-14 00:38

    Remember variable names are just pointers to objects in memory.

    The == operand compares the pointers. It will not be true unless it is comparing the exact same object in memory.

    isEqualToString: is your best bet. Don't worry too much about speed. The devices are plenty fast enough to do the comparison in the blink of an eye. The things that really take noticible time are drawing on screen and reading from disk.

提交回复
热议问题