dictionary的使用要注意

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
                           };

猜你喜欢

转载自duchengjiu.iteye.com/blog/2190455