assignment makes pointer from integer without a ca

2019-01-29 06:01发布

问题:

I don't understand what is problem here! after I compile it, always show me: "assignment makes pointer from integer without a cast" I don't know what is the problem! Please let me, thanks.

SAVE

 NSUserDefaults *percentChecker = [NSUserDefaults standardUserDefaults]; 
 [percentChecker setInteger:0 forKey:percentCheckerSaveKey];

LOAD

NSUserDefaults *percentChecker = [NSUserDefaults standardUserDefaults]; 
NSString *percentString;

//Alert! 
percentString = [percentChecker integerForKey:percentCheckerSaveKey];

回答1:

It's exactly what it's telling you. percentString is a pointer, but integerForKey: returns an integer. Assigning that integer to a pointer is making a "pointer from an integer without a cast". Why are you saving an integer and trying to load it later as a string?