我从服务器获取一些数据并将其保存到NSDictionary
然后我想NSMutableDictionary
用它进行初始化NSDictionary
。
NSDictionary * const received = [self serverData];
NSMutableDictionary * const results = [NSMutableDictionary dictionaryWithDictionary:received];
如果我从服务器得到空的 JSON,因此我的NSDictionary
将是空的,我该如何使用dictionaryWithDictionary
一个空的 JSON?我用这个
NSDictionary * const received = [self serverData];
NSMutableDictionary * const results;
if (![received count]) {
results = [NSMutableDictionary dictionary];
}
else
{
results = [NSMutableDictionary dictionaryWithDictionary:received];
}
但这似乎是一种代码气味。可能有更优雅的解决方案吗?