当我登录一个应该是NSNumber
的变量时,它给了我0我认为这意味着它是nil
我想排除这种情况。如果它是零,我也想排除它。我只想确定1,2,3中有数字的情况。Objective-C:测试零/ 0值?
但是,我已经尝试了以下,没有一个成功地排除了变量记录为0但包括记录到1,2,3等的情况。任何人都可以建议我做错了什么。
if (self.number!=nil) //fails to exclude
if (self.number) //fails to exclude
if (self.number.length>0)//returns error
if (self.number!=nil&&self.number!=0) //fails to exclude
of note if (!self.number) //does exclude but it also excludes case where self.number is 2, 3 or any other number.
感谢您的任何建议
OP在他们发布的第一行代码中执行此操作。 – rmaddy
好的。我在你的答案中加入了一个变体。如果(self.number!-nil && self.number.integerValue!= 0)Thx! – user1904273
@rmaddy我意识到这一点,我试图说明我的例子中的差异。 –