ios - How to use shared preference in xcode using objective-c? -
this question has answer here:
in 1 view controller, store array value , value view controller. how save array value in shared manager , how retrieve array value view controller? how use shared preference in xcode? possible? please me example.thank you.
my code is
(id)sharedmanager {
static assistantview *sharedmymanager = nil;
static dispatch_once_t oncetoken;
dispatch_once(&oncetoken, ^{ sharedmymanager = [[self alloc] init]; });
return sharedmymanager; }
and put value
[[assistantview sharedmanager]results]; // results array
use nsuserdefaults
set
[[nsuserdefaults standarduserdefaults] setobject:@"your object" forkey:@"nameofpreference"]; [[nsuserdefaults standarduserdefaults] synchronize]; get
nsstring *savedobject = [[nsuserdefaults standarduserdefaults] stringforkey:@"nameofpreference"]; // object alternative using appdelegate
1 define macro
#define appdelegate ((appdelegate *)[[uiapplication sharedapplication] delegate]) 2 add property object in appdelegate
@property (nonatomic) nsarray *arrobjects; 3 set object property .
appdelegate.arrobjects = @[@"",@""]; 4 value
nsarray *globalobjects = appdelegate.arrobjects
Comments
Post a Comment