【问题标题】:NSCalendar currentCalendar returns nil when called inside cocoapod?NSCalendar currentCalendar 在 cocoapod 内调用时返回 nil?
【发布时间】:2014-06-30 19:02:48
【问题描述】:

我正在为 NSDate 创建一个类别,以添加诸如 [date isEquivalentToToday] 之类的方法。我让这个类别工作得很好,然后进入了一个定制的 cocoapod。我一这样做,它就停止了工作。事实证明这是因为 [NSCalendar currentCalendar] 和 [calendar components:fromDate] 在 cocoapod 中调用时似乎根本不起作用。谁能解释为什么会这样以及是否有办法使它起作用?

如果您需要一些代码来查看这是我在 isEquivalentToToday 顶部所做的:

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:[NSDate date]];
NSDate *today = [calendar dateFromComponents:components];

当此代码包含在应用程序本身中时,它会返回一个表示今天的 NSDate,其时间分量为零。

只要我将相同的代码移入 cocoapod 并让我的应用程序调用它,前两行就会返回 nil。

我尝试将一个有效的 NSCalendar 对象传递给 cocoapod,但是 components:fromDate: 方法仍然返回 nil。

我宁愿不只是将此代码拉回到我的项目中,因为将它拆分成一个可重用的 pod 非常好。但现在我看不到任何其他方法可以让它再次工作。其他人之前遇到过这种情况吗?

【问题讨论】:

    标签: ios nsdate cocoapods nscalendar


    【解决方案1】:

    在花更多时间研究之后,看起来代码实际上运行正常,但是当我进入 pod 或在其中的断点处停止时,调试器没有报告正确的信息。

    我能够通过将此代码移回我的主项目来解决此问题。

    【讨论】:

    • 现在遇到了同样的行为。 currentCalendar 根据调试器返回 nil 但在记录时它就在那里。
    • 查看我最近的编辑:在我的情况下,我可以通过将日历代码从我制作的 cocoapod 移回我的主项目来解决问题。
    猜你喜欢
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多