gpt4 book ai didi

ios - 相同的对象但具有不同的内容(目标 - C)

转载 作者:行者123 更新时间:2023-11-29 00:14:51 26 4
gpt4 key购买 nike

我有这样的方法:

+ (PlayListModel *)transferToPlayListModelWithModel:(HomeLooperInfoDataResponseModel *)model{

PlayListModel * listModel = [PlayListModel new];

listModel.isDaily = NO;
listModel.idField = model.idField;
listModel.title = model.title;
listModel.url = model.url;
listModel.type = model.type;
listModel.pictureUrl = model.pictureUrlBig;

listModel.price = model.price;
listModel.discount_price = model.discount_price;
listModel.live_count = model.live_count;
listModel.webViewIntroURL = model.live_url;

listModel.isCost = model.isCost;
listModel.is_live = model.is_live;
listModel.live_end_time = model.live_end_time;
listModel.live_start_time = model.live_start_time;
listModel.is_recording = model.is_recording;

return listModel;

}

非常简单,我在这里调用它:

PlayListModel *model = [PlayListModel transferToPlayListModelWithModel:currentModel];
NSLog(@"%@",model);

然后,它向我展示了相同的对象 model 具有不同的内容: enter image description here我希望属性 isDaily 为 No,但它返回 yes,这让我很困惑。我确实写了 listModel.isDaily = NO 。不知道哪里出了问题。

附注这是我的描述方法:

- (NSString *)description{
unsigned int count;
const char *clasName = object_getClassName(self);
NSMutableString *string = [NSMutableString stringWithFormat:@"<%s: %p>:[ \n",clasName, self];
Class clas = NSClassFromString([NSString stringWithCString:clasName encoding:NSUTF8StringEncoding]);
Ivar *ivars = class_copyIvarList(clas, &count);
for (int i = 0; i < count; i++) {
@autoreleasepool {
Ivar ivar = ivars[i];
const char *name = ivar_getName(ivar);

NSString *type = [NSString stringWithCString:ivar_getTypeEncoding(ivar) encoding:NSUTF8StringEncoding];
NSString *key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
id value = [self valueForKey:key];

if ([type isEqualToString:@"B"]) {
value = (value == 0 ? @"NO" : @"YES");
}
[string appendFormat:@"\t%@: %@\n",[self delLine:key], value];
}
}
[string appendFormat:@"]"];
return string;
}

最佳答案

左下角的输出是正确的值。试试这个 NSLog(@"%@", model.isDaily) 看看结果。

右下角的输出是基于当前类或父类中实现的方法-(void)description,也许在这个方法中你改变了属性isDaily;

关于ios - 相同的对象但具有不同的内容(目标 - C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45498061/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com