//Amodel的h及m文件代碼
@class Bmodel;
@interface Amodel :NSObject
@property (nonatomic, strong)Bmodel *model;
@end
@implementation Amodel
- initWithDic:(NSDictionary *)dic {
? ? ? ?if (self = [super init]) {
? ? ? ? ? ? ? [self setValuesForDictionary:dic];
? ? ? ?}
}
- setModel:(NSDictionary *)dic {
? ? ? ? Bmodel *model = [Bmodel modelWithDic:dic];
? ? ? ? self.model = model;
}
@end
//Bmodel的m文件部分代碼
@implementation
- (Bmodel *)modelWithDic:(NSDictionary *)dic {
? ? ? ? ?return [Bmodel alloc] initWithDic:dic];?
}
- initWithDic:(NSDictionary *)dic {
? ? ? ? if (self = [super init]) {
? ? ? ? ? ? ? [self setValuesForDictionary:dic];?
? ? ? ? }
}
@end
//以上代碼會崩潰 ?而且如果第一次找到崩潰位置 將崩潰代碼注釋掉 就會在其他(不做具體描述了)地方崩潰 ?原因是KVC不能識別自己建立的類型; ?遇到這種情況 可以使用JsonModel三方庫 或者故意將類型為model類型的名字寫錯 ?然后重寫 - valueForUnfindKey : ? -setValue:ForUnFindKey:方法 ?在第二個方法中重新賦值
(以上代碼純手寫 可能會有很多單詞字母錯誤的地方 ?我盡然懶到不想command + c/v ??)