(2012-07-10 18:31:24)html
轉載▼session
標籤: 雜談 |
分類: iphone開發 |
NSString *sessionId = @"123";iphone
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];spa
[defaults setObject:sessionId forKey:@"sessionID"];orm
[defaults synchronize];htm
NSString *value; blog
value = [defaults objectForKey:@"sessionID"]; //獲取值ip
Savingci
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];開發
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];
// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize]; //同步,寫到磁盤中;
Retrieving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];
// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];
NSUserDefaults只支持: NSString, NSNumber, NSDate, NSArray, NSDictionary.