0

当我将 Xcode 更新到 4.4.1 时,它给了我 22 个使用 RestKit 库的警告。错误是这样的:

Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()

我通过替换修复了 18 个警告:

替换%lu%u

替换object->isaobject_getClass(object)

替换keyObject->isaobject_getClass(keyObject)

还有 4 个我无法修复的警告,以下是警告及其描述:

文件名 1:RKManagedObjectMappingOperation.m 警告行 1:

NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.");

警告说明1:

more '%' conversations than data arguments

文件名 2:RKReachabilityObserver.m 警告行 2:

return [NSString stringWithFormat:@"<%@: %p host=%@ isReachabilityDetermined=%@ isMonitoringLocalWiFi=%d reachabilityFlags=%@>",
            NSStringFromClass([self class]), self, self.host, self.isReachabilityDetermined ? @"YES" : @"NO",
            self.isMonitoringLocalWiFi ? @"YES" : @"NO", [self reachabilityFlagsDescription]];

警告说明2:

format specifies type int but the argument has type NSString

文件名 3:JSONKit.m 警告行 3:

if(JK_EXPECT_F(((id)keys[idx])->isa != encodeState->fastClassLookup.stringClass) && JK_EXPECT_F([(id)keys[idx] isKindOfClass:[NSString class]] == NO)) { jk_encode_error(encodeState, @"Key must be a string object."); return(1); }

警告说明3:

Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()

文件名 4:NSManagedObject+ActiveRecord.m 警告行 4:

RKLogError(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self));

警告说明4:

format specifies type id but the argument has type NSUInteger

如何解决?

4

1 回答 1

1

警告1:

NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.");

变成

NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.", <<put the corresponding keyPath here >> );

或者

NSAssert(mapping, @"Attempted to connect relationship for a keyPath without a relationship mapping defined.");

它说“比数据参数更多的'%'对话”意味着你有占位符,在这种情况下是%@,但没有参数来填充它们。所以要么提供一个参数,要么删除占位符。

警告 2:

return [NSString stringWithFormat:@"<%@: %p host=%@ isReachabilityDetermined=%@ isMonitoringLocalWiFi=%d reachabilityFlags=%@>",
        NSStringFromClass([self class]), self, self.host, self.isReachabilityDetermined ? @"YES" : @"NO",
        self.isMonitoringLocalWiFi ? @"YES" : @"NO", [self reachabilityFlagsDescription]];

变成

return [NSString stringWithFormat:@"<%@: %p host=%@ isReachabilityDetermined=%@ isMonitoringLocalWiFi=%@ reachabilityFlags=%@>",
        NSStringFromClass([self class]), self, self.host, self.isReachabilityDetermined ? @"YES" : @"NO",
        self.isMonitoringLocalWiFi ? @"YES" : @"NO", [self reachabilityFlagsDescription]];

请注意isMonitoringLocalWiFi=%d部分获取%@而不是%d,因为您提供了一个字符串参数但有一个整数占位符。

警告 3:抱歉,无法帮助您解决此问题。可能在我查看代码之后,我会发布更新。

更新:尝试更改

((id)keys[idx])->isa

object_getClass( ((id)keys[idx]) )

警告 4:

RKLogError(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self));

变成

RKLogError(@"Property '%@' not found in %d properties for %@", propertyName, [propDict count], NSStringFromClass(self));

注意第二个占位符应该是%d而不是%@因为你提供了一个整数,或者在这种情况下是一个 NSUInteger,即[propDict count]参数。

于 2012-09-08T00:19:44.443 回答