【问题标题】:NSAssert undeclared first use why?NSAssert 未声明第一次使用为什么?
【发布时间】:2011-07-29 07:51:39
【问题描述】:

我在levelManager.m 中使用下面的代码从 plist 中读取值,但是当我制作存档以上传到 itunes (AppStore) 时出现错误。为什么?

代码:

- (float)floatForProp:(NSString *)prop {
NSNumber * retval = (NSNumber *) [_curStage objectForKey:prop];
NSAssert (retval != nil, @"Couldn't find prop %@", prop);
return retval.floatValue;
}

错误:

NSAssert 未声明的首次使用

注意我注意到 xcode 认为我给 NSAssert 3 个参数而不是 2 个

【问题讨论】:

    标签: iphone ios archive llvm nsassert


    【解决方案1】:

    您可以使用NSAssert 变体之一,在您的情况下为NSAssert1

    #define NSAssert1(condition, desc, arg1)
    

    所以:

    #import <Foundation/Foundation.h>
    
    - (float)floatForProp:(NSString *)prop
    {
      NSNumber * retval = (NSNumber *) [_curStage objectForKey:prop];
      NSAssert1 (retval != nil, @"Couldn't find prop %@", prop);
      return retval.floatValue;
    }
    

    感兴趣的post 和苹果的Assertions and Logging Programming Guide 相关。

    【讨论】:

      【解决方案2】:

      替换为

      NSAssert (retval != nil, ([NSString stringWithFormat:@"Couldn't find prop %@", prop]));
      

      【讨论】:

        【解决方案3】:

        如果你认为它认为你给出了三个参数,使用这个:

        NSAssert (retval != nil, [NSString stringWithFormat:@"Couldn't find prop %@", prop]);
        

        【讨论】:

          猜你喜欢
          • 2011-09-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多