0
点赞
收藏
分享

微信扫一扫

dictionary的使用要注意

ZMXQQ233 2022-08-05 阅读 178


NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
user.user_id , @"id",
user.username , @"username",
nil];

 例如这样使用的时候, 因为这个方法一旦遇到nil, 这个字典就结束了, 如果user.user_id 为nil, 则字典为空, 如果user.username为nil, 则username这个key-value就存储不了, 出现问题可能比较难找

 

建议使用

NSDictionary *dict = @{
@"id":user.user_id,
@"username":user.username
};

 

举报

相关推荐

0 条评论