Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
// getting an NSString NSString *myString = [prefs stringForKey:@"keyToLookupString"];
You should really check out Apple's NSUserDefaults Class Reference and also maybe this tutorial: iPhone Programming Tutorial – Saving/Retrieving Data Using NSUserDefaults
I would like to ask if there is any possibility to save image same way??? and if I can save more images this way???
like [[NSUserDefaults standardUserDefaults] setValue:myImage1 forKey:@"1"] [[NSUserDefaults standardUserDefaults] setValue:myImage2 forKey:@"2"] and so on...... and save it on app quitting .....and when starting again load it like this .......
NSString *valueToSave = @"someValue";
ReplyDelete[[NSUserDefaults standardUserDefaults]
setObject:valueToSave forKey:@"preferenceName"];
to get it back later
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"preferenceName"];
more precisely
ReplyDelete-(void)saveToUserDefaults:(NSString*)myString
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults) {
[standardUserDefaults setObject:myString forKey:@"timestamps"];
[standardUserDefaults synchronize];
}
}
Something like this:
ReplyDeleteNSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
Then to retrieve:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];
You should really check out Apple's NSUserDefaults Class Reference and also maybe this tutorial: iPhone Programming Tutorial – Saving/Retrieving Data Using NSUserDefaults
[[NSUserDefaults standardUserDefaults] setValue:aString forKey:aKey]
ReplyDeleteI would like to ask if there is any possibility to save image same way??? and if I can save more images this way???
ReplyDeletelike [[NSUserDefaults standardUserDefaults] setValue:myImage1 forKey:@"1"]
[[NSUserDefaults standardUserDefaults] setValue:myImage2 forKey:@"2"] and so on...... and save it on app quitting .....and when starting again load it like this .......
UIImage *myImage1 = [[NSUserDefaults standardUserDefaults] imageForKey:@"1"];
is it possible?????