search

Home  >  Q&A  >  body text

ios - 往字典里赋值有时候不成功的原因???

例1. NSMutableDictionary *dicPara = [NSMutableDictionary dictionaryWithObjectsAndKeys:_address,@"address",lonti,@"longtitude",lati,@"latitude",_poiname,@"poiname",_province,@"province",_city,@"city",_district,@"district",_street,@"street",nil];
例2. NSMutableDictionary *dicPara = [NSMutableDictionary dictionaryWithObjectsAndKeys:_addressL,@"address",lonti,@"longtitude",lati,@"latitude",remark,@"remark",customer_id,@"customer_id",nil];
[dicPara setObject:POIName forKey:@"poiname"];
[dicPara setObject:province forKey:@"province"];
[dicPara setObject:city forKey:@"city"];
[dicPara setObject:district forKey:@"district"];
[dicPara setObject:street forKey:@"street"];

例1是我开始写的,打印字典,发现里面的值有一部分不存在的
然后我采取了下面例2的赋值方法,发现赋值成功了虽然成功了,但是我不知道原因是什么,请大神指点迷津

天蓬老师天蓬老师2771 days ago414

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 09:53:21

    dictionaryWithObjectsAndKeys When using this method to initialize a variable dictionary, you need to ensure that the value inside the dictionary is not empty. If it is empty, after the dictionary receives the empty value, it will default to all subsequent key values ​​​​as empty and will be removed.
    For example:

    The difference between the setValue method and the setObject method is that the setValue method will call the setObject method. If the value is empty, the removeObject method will be called

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:53:21

    Dictionary container cannot store nil

    reply
    0
  • Cancelreply