Created
June 20, 2017 11:53
-
-
Save yabenatti/0b180a4c65d90195637cbc9de41dbf68 to your computer and use it in GitHub Desktop.
Saving content to UserDefault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - User Defaults | |
//Saves information on cache | |
+ (void)saveToUserDefault:(NSObject*)objectToSave withKey:(NSString*)key { | |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | |
[userDefaults setObject:objectToSave forKey:key]; | |
[userDefaults synchronize]; | |
} | |
//Retrieves information from cache | |
+ (NSObject*)retrieveFromUserDefaultWithKey:(NSString*)key { | |
return [[NSUserDefaults standardUserDefaults] objectForKey:key]; | |
} | |
//Clears all cache (used on logout for example) | |
+ (void)clearUserDefault { | |
[AppUtils saveToUserDefault:nil withKey:API_TOKEN]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment