objective-c - ios model 有一个属性也是model类型,初始化时,进入死循环,怎么破?

浏览:61日期:2023-12-13

问题描述

(instancetype)initFromDictionary:(NSDictionary *)dictionary{ShowLog self = [super init]; if (self) {

_cid= StringValue(dictionary, KID); _user = [[User alloc] initFromDictionary:DictionaryValue(dictionary, Kuser)]; _images = ArrayValue(dictionary, Kimages); _content = StringValue(dictionary, Kcontent); //_beCommented= [[Comment alloc] initFromDictionary:DictionaryValue(dictionary, KbeCommented)]; _createTime = DateValue(dictionary, KcreateTime); _ownerId = StringValue(dictionary, KownerId);

} return self;}

注释那个行使程序进入了死循环,这个要怎么改?

问题解答

回答1:

属性用getter方法初始化加载也很方便,一个方法里面又要调用自己,需要有一个结束条件。

相关文章: