@Legend_劉先森 我这边需求是将项目中的NSUserDefaults存储的内容进行加密,所以用自定义方法替换了setObject:forKey:和objectForKey:,分别在新的方法里进行对数据的加解密,但是ZDY_newObjForKey方法里用修改的object值return后老是崩溃,求解
@implementation NSUserDefaults (ZDYUserDefaults)
+ (void)load {
Method fromMethod = class_getInstanceMethod([self class], @selector(setObject:forKey:));
Method toMethod = class_getInstanceMethod([self class], @selector(ZDY_setNewObj:forKey:));
method_exchangeImplementations(fromMethod, toMethod);
Method fromMethod1 = class_getInstanceMethod([self class], @selector(objectForKey:));
Method toMethod1 = class_getInstanceMethod([self class], @selector(ZDY_newObjForKey:));
method_exchangeImplementations(fromMethod1, toMethod1);
}
- (void)ZDY_setNewObj:(id)object forKey:(id)key {
object = @"1111111";
[self ZDY_setNewObj:object forKey:key];
}
- (id)ZDY_newObjForKey:(id)key{
id object = [self ZDY_newObjForKey:key];
if ([object isKindOfClass:[NSNull class]]) {
object = @"";
}else{
object = @"222222";
}
return object;
}
@end
iOS中Runtime的常用方法Runtime是什么? Apple关于Runtime的详细文档链接:Runtime Guide其实大家对Runtime算是既熟悉又陌生的,因为在学习Objective-C的时...