当我将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 警告Line1:
NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.");
警告说明1:
more '%' conversations than data arguments
文件名2:RKReachabilityObserver.m 警告Line2:
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 警告Line3:
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
如何解决?
答案 0 :(得分: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]
参数。