如果我有一个看起来像这样的方法:
- (NSDictionary *)removeDataInDictionary:(NSDictionary *)dictionary {
NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];
[mutableDictionary removeObjectForKey:@"key"];
// Return option 1
return [NSDictionary dictionaryWithDictionary:mutableDictionary];
// Return option 2
return (NSDictionary *) mutableDictionary;
}
选项 1 在代码方面是否“更好”,因为它真的会返回 aNSDictionary
而选项 2 实际上会返回NSMutableDictionary
伪装成 a 的NSDictionary
?