今天在看以前写的代码的时候,发现在比较两个NSNumber大小的时候直接写成了 a > b(ab都是NSNumber对象),竟然没有保存,结果也符合预期。可以似乎对象之间不能直接用关系运算符比较,而是应该使用compare:方法啊。有人注意到这一点吗?
compare:
ringa_lee
Is it swift? If so the operator may be overloaded.
If it’s OC, it’s a coincidence:) It’s probably two pointer addresses that are being compared.
Is it swift? If so the operator may be overloaded.
If it’s OC, it’s a coincidence:) It’s probably two pointer addresses that are being compared.