NSDate 变成 NSNumber 之谜

发布于 2024-12-27 21:49:39 字数 692 浏览 4 评论 0原文

我正在 iOS 4.3 & 中工作iOS 5 具有自动引用计数功能。我在界面中声明了一个 NSDate 对象:

NSDate *fingerprintsDate;

后来,我设置了 NSDate - 使用调试器并逐步执行它具有我期望的值:

fingerprintsDate = [NSDate date];

最后,我尝试从日期中获取时间:

if (fingerprintsDate == nil || [fingerprintsDate timeIntervalSinceNow] > 6)

这就是它因无法识别而崩溃的地方选择器:“2012-01-18 23:07:46.662 Netapporter[473:707] -[NSCFNumber timeIntervalSinceNow]:无法识别的选择器发送到实例 0x194490”

根据调试器,我亲爱的 NSDate 读到:“fingerprintsDate = (NSCFNumber *) 0x194490 139” - 当我打印描述时,它读到:“{value = +139.0000000000,type = kCFNumberFloat32Type}

”不做任何其他带有指纹的事情代码 - 但不知何故它变成了 NSNumer...有什么想法如何阻止它吗?

I'm working in iOS 4.3 & iOS 5 with automatic reference counting. I declare a NSDate object in my interface:

NSDate *fingerprintsDate;

Later, I set that NSDate - using the debugger and stepping through it has the value I'd expect:

fingerprintsDate = [NSDate date];

Finally, I try to get the time from the date:

if (fingerprintsDate == nil || [fingerprintsDate timeIntervalSinceNow] > 6)

And that's where it crashes with unrecognized selector: "2012-01-18 23:07:46.662 Netapporter[473:707] -[NSCFNumber timeIntervalSinceNow]: unrecognized selector sent to instance 0x194490"

According to the debugger, my dear NSDate reads: "fingerprintsDate = (NSCFNumber *) 0x194490 139" - when I print description it reads: "{value = +139.0000000000, type = kCFNumberFloat32Type}"

I'm not doing anything else w/ fingerprintsDate anywhere else in the code - but somehow it's turning into an NSNumer... Any ideas how to stop it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2025-01-03 21:49:39

[NSDate date] 返回一个非保留值(如果您使用 arc,则为弱值),因此它很可能在该赋值和调用 [fingerprintsDate timeIntervalSinceNow] 之间的某个位置被释放。当您将其分配给保留(强)属性时,它就会被保留。

[NSDate date] returns a non-retained value (or weak if you're using arc), so it most likely got released somewhere between that assignment and calling [fingerprintsDate timeIntervalSinceNow]. When you assign it to a retained (strong) property, it's being retained.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文