【问题标题】:Can I change (unsigned) to (NSUInteger) or will it create problems?我可以将 (unsigned) 更改为 (NSUInteger) 还是会产生问题?
【发布时间】:2015-10-03 07:09:07
【问题描述】:

我是一名初级软件开发人员,我可以将 (unsigned) 更改为 (NSUInteger) 还是稍后会产生问题?

- (unsigned)retainCount
{
    return UINT_MAX;  //denotes an object that cannot be released
}

警告说

MKStoreManager.m:88:1: Conflicting return type in implementation of 'retainCount': 'NSUInteger' (aka 'unsigned long') vs 'unsigned int'

我找到了以前的定义

- (NSUInteger)retainCount OBJC_ARC_UNAVAILABLE;

【问题讨论】:

    标签: ios objective-c unsigned nsuinteger


    【解决方案1】:

    您的方法必须返回NSUInteger,因为retainCount 方法在NSObject 中是这样定义的。

    错误是由您尝试返回的值引起的。您应该返回NSUIntegerMax,而不是返回UINT_MAX

    NSUInteger 的基础类型根据构建为 32 位还是 64 位而有所不同。相应地,NSUIntegerMax 的值也会发生变化以匹配类型。

    - (NSUInteger)retainCount
    {
        return NSUIntegerMax;  //denotes an object that cannot be released
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2023-04-03
      • 2017-11-21
      • 2016-09-24
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      相关资源
      最近更新 更多