I’m just starting with Objective C and xcode. I’ve been exploring NSUserdefaults.
I can save my text field’s input to the plist file. Nad can retrive it to a label when the application launches again.
What I can’t do is get an alternative text to show IF the plist key is empty. Using the code below my label is just empty until I add text back to the plist via the text field. Any pointers please?
- (void)viewWillAppear:(BOOL)animated;
{
NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
NSString *theNewString=[ud objectForKey:@"textFieldKey"];
// update the label
if (theNewString) {
[mylabel setText:theNewString];
} else {
[mylabel setText:@"nothing stored"];
}
}
Handling the case of a nil string or a valid string of length 0 (empty):