Reputation: 744
I know there are many ways for storing data like property list,archiving etc..but other than that is there any other way for storing very small amount of data,which is common to different view controllers(like a common class for storing all the data)?.
Upvotes: 1
Views: 140
Reputation: 5384
Try this
when you want to save small amounts of data such as High Scores, Login Information, and program state.
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"];
[prefs synchronize];
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"];
Upvotes: 2
Reputation: 2243
Yes you can declare in forms of NSMutableArray or NSMutableDictionary and access it any Viewcontrollers. You need to create a file as NSObject class and in
.h
+(NSMutableDictionary *)ImageCollection;
in .m file
+(NSMutableDictionary *)ImageCollection
{
static NSMutableDictionary *thestring =nil;
@synchronized([Global class]) // in a single threaded app you can omit the sync block
{
if (thestring ==nil) {
thestring=[[NSMutableDictionary alloc]init];
}
}
return thestring;
}
In any View Controllers include that NSObject class file
[[Global ImageCollection]setObject:@"Sample" forKey:@"Dictionary"]; //just example you can save string,image,array anything as you like
Hope this helps .. !!!
Upvotes: 0
Reputation: 439
Yes, you can define the required fields in form of an array. Now make sure that the form will provide you an identity and there is some validation through session etc. A a hook to your controller to sense the form submission every time with a particular flag (hidden). So the tablename and CRUD instruction will be provided to this function and every common CRUD functionality will be handled by this single function. By defining the required fields will let you ignore the extra ones like input buttons and many hidden fields.
Upvotes: 1