NSDate 变成 NSNumber 之谜
我正在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[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.
你是用GBD调试,用GCC编译吗?可能与我的问题有关: -[NSDate timeIntervalSinceDate:] 在 GCC 4.2 上返回非常小的数字,但在 LLVM-GCC 4.2 上按预期工作在iOS4.3模拟器上
Are you debugging with GBD, compiling with GCC? Could be related to my question: -[NSDate timeIntervalSinceDate:] returns very small number on GCC 4.2, but works as expected on LLVM-GCC 4.2 on iOS4.3 Simulator