当我将 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->isa
替换为object_getClass(object)
将 keyObject->isa
替换为 object_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
如何解决?
最佳答案
警告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]
参数。
关于iphone - RestKit 更新到 xcode 4.4.1 后出现警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12326853/