如果我们有一个 API 只需要对象 5 个属性中的 2 个,而 iPhone 应用程序不需要它们来实例化一个对象,那么当在参数 NSDicitionary 中使用该对象时,应用程序将崩溃。有人告诉我 NSDictionary 不会让你分配 nil 值,因为当它达到 nil 时,它认为它已经完成了。Objective-c 是否有办法将对象的非 nil 属性吐出到 NSDictionary 中?
例子:
[Drunk alloc] init];
drunk.started_drinking = [NSDate date];
drunk.stopped_drinking (we don't set this because he is still a drunk)
drunk.fat = YES;
drunk.dumb = YES;
parameters:@{
@"auth_token" :token,
@"name" : drunk.name, @"date_started" : drunk.started_drinking,
@"date_stopped" : drunk.stopped_drinking,
@"prescribing_doctor" : drunk.fat,
@"pharmacy" : drunk.dumb
}
当它到达stopped_drinking 属性时,这将崩溃。有关如何处理此问题的任何建议?