How to allow NSMutableDictionary to accept 'nil' values?

后端 未结 3 2106
遇见更好的自我
遇见更好的自我 2021-02-12 16:01

I have this statement:

 [custData setObject: [rs stringForColumnIndex:2]  forKey: @\"email\"];

where [rs stringForColumnIndex:2] o

3条回答
  •  面向向阳花
    2021-02-12 16:46

    I needed to set a NSDictionary value to one that may or may not be set yet from NSUserDefaults.

    What I did was wrap the values in a stringwithFormat call. Both values are not yet set so start as null. When I run without the stringwithFormat call the app crashes. So I did this and in my situation worked.

    -(NSDictionary*)userDetailsDict{
    NSDictionary* userDetails = @{
                                  @"userLine":[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]stringForKey:kSelectedLine] ],
                                  @"userDepot":[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]stringForKey:@"kSelected Duty Book"]]
                                  };
    
    return userDetails;
    }
    

提交回复
热议问题