Keyword: nsuserdefaults NSNull Nil
Recently, in some code you see the following notation:
1Nsuserdefaults *user =[Nsuserdefaults standarduserdefaults];2 3NSString *count = [user objectforkey:@"Count"];4NSString *pass = [user objectforkey:@"Pass"];5 6 if((nsnull*) Count = = [NSNullNULL])//empty, when Count is null, it will be in if, anti-collapse, because if it is empty, also need to use, it may collapse7 {8 return;9}
The result of the code comment was not obtained by experiment. The first time you run this code, count and pass are nil. (NSNull *)countafter conversion, or nil, and [NSNull null] do = = operation, the result is false, can not achieve defensive programming purposes. The debug code and the results are as follows:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { *hello = [[Nsuserdefaults standarduserdefaults] Valueforkey:@ "Hello"]; if NULL]) // empty, when Count is null, it will be in if, anti-collapse, because if it is empty, also need to use, it may collapse { return YES; } return YES;}
IOS 8:nsnull is not valid in nsuerdefaults empty processing