【问题标题】:Comparing two NSIntegers results in < nil > instead of false比较两个 NSInteger 的结果是 < nil > 而不是 false
【发布时间】:2014-08-14 16:42:38
【问题描述】:

在进行减法后比较两个 NSInteger 时遇到一个奇怪的问题,任何想法为什么这个比较返回“”而不是 false?我检查以确保调试器中的所有变量都有值

    NSInteger totalPhotosLeft = self.totalPhotosInRoll - self.currentPhotosFetchedCount;
    if (self.enumerateCount < totalPhotosLeft) {
        ...//never goes here, comparison above always returns < nil >
    }

我的属性

@property (nonatomic) NSInteger currentPhotosFetchedCount;
@property (nonatomic) NSInteger enumerateCount;
@property (nonatomic) NSInteger totalPhotosInRoll;

viewDidLoad

self.currentPhotosFetchedCount = 60;
self.enumerateCount = 15;
self.totalPhotosInRoll = 65;

【问题讨论】:

  • 返回“”是什么意思?
  • 当我签入调试器时: po self.enumerateCount "
  • 使用p self.enumerateCount &lt; totalPhotsLeftpo 用于 print object。这不是一个对象。
  • 啊,谢谢!我把它写成答案

标签: ios objective-c ios7 comparison nsinteger


【解决方案1】:

在调试时,我使用的是 po 而不是 p。 po 用于打印对象,p 用于一般打印。

感谢@rmaddy 这么快就解决了这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多