【问题标题】:Error passing NSNumber to UInt32将 NSNumber 传递给 UInt32 时出错
【发布时间】:2012-05-09 01:10:19
【问题描述】:

我正在尝试将 NSNumber 传递给 UInt32 变量,它似乎可以工作,但是当我去记录 UInt32 的值时,我卡住了。

这就是我的代码的样子。

if ([methodName isEqualToString:@"Manu"]) {
        cacheNumber = [cacheValue objectForKey:@"Manus"];

        NSLog(@"%@", cacheNumber); // This produces the correct number
    }

    UInt32 CACHE_VALUE = [cacheNumber intValue];
    NSLog(@"%@", CACHE_VALUE); // This is where my thread gets stuck

这是我尝试单步执行第二个 NSLog 时产生的消息(因为我在两个日志上都有断点来检查它们的输出)。

单步执行直到退出函数 objc_msgSend,它没有 行号信息。

任何帮助将不胜感激

【问题讨论】:

  • 问题出在您的 NSLog 中。 CACHE_VALUE 不是对象。

标签: iphone ios nsnumber uint32


【解决方案1】:

您打印的是 NSString 而不是 UInt。

    NSLog(@"%lu", CACHE_VALUE); // This is where my thread gets stuck

【讨论】:

  • 哦,废话..我应该看到的..我的坏。真是个菜鸟。谢谢。
  • 很快就会接受您的回答。实际上只是在 xcode 中尝试过,它告诉我使用 @"%lu",...所以我更新了你的解决方案
【解决方案2】:

当您记录一个整数而不是一个对象时,即。一个 NSString,你应该使用 %d(十进制)占位符而不是 %@(对象)。

NSLog(@"Value: %d", CACHE_VALUE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2020-06-26
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多