开发者

Pointers In Objective C

开发者 https://www.devze.com 2023-03-15 12:08 出处:网络
How do I compare two pointers in 开发者_JAVA技巧objective C without using the compare operator \"isEqualToString\"? Please help if any alternate.

How do I compare two pointers in 开发者_JAVA技巧objective C without using the compare operator "isEqualToString"? Please help if any alternate.

Thanks.


If you really want to compare two pointers in objc (which I doubt) you could use the standard "==" operator.

if(mypointer1==mypointer2){}

By the way, doing so you are not comparing the data of the objects pointed by the pointers, but simply the numeric value of the pointers itself (aka their address).

If you want to compare two objects you could use (if they implement it)

isEqual. Finally, if you are comparing two strings, you should use

isEqualToString:


Just wanted to chime to clarify that the use of str1==str2 will (correctly) tell you if the pointer (technically references in objc) are equal.

However (starting in iOS 8.x (and possibly earlier)), you will get a warning stating that the result is "undefined"

0

精彩评论

暂无评论...
验证码 换一张
取 消