Objective-C constants: NSString comparison using ==?

▼魔方 西西 提交于 2019-12-01 06:44: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.

== does pointer comparison, it won't compare the values of two objects. isEqualToString: (and in general isEqual:) is the right way to do this - where was it described as a "bad solution"?

Who described that as a bad solution? It is the only proper/correct solution to the problem at hand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!