@Legend_劉先森 我這邊需求是將項(xiàng)目中的NSUserDefaults存儲(chǔ)的內(nèi)容進(jìn)行加密惫搏,所以用自定義方法替換了setObject:forKey:和objectForKey:跃捣,分別在新的方法里進(jìn)行對(duì)數(shù)據(jù)的加解密焰情,但是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關(guān)于Runtime的詳細(xì)文檔鏈接:Runtime Guide其實(shí)大家對(duì)Runtime算是既熟悉又陌生的瓣窄,因?yàn)樵趯W(xué)習(xí)Objective-C的時(shí)...