Create Global NSMutableArray, NSMutableDictionary,NSUserDefaults

Create a Class named globaldict Under the Subclass of NSObject In globaldict.h +(NSMutableDictionary *) somename; +(NSMutableArray*) somename1; +(NSUserDefaults*) somename2; In globaldict.m +(NSMutableDictionary*) somename { static NSMutableDictionary* theValue = nil; @synchronized([globaldict class]) // in a single threaded app you can omit the sync block { if (theValue == nil) { theValue = [[NSMutableDictionary alloc] init]; } } return theValue; } +(NSMutableArray*) somename1 { static NSMutableArray* theValue = nil; @synchronized([globaldict class]) // in a single threaded app you can omit the sync block { if (theValue ==…

Continue reading »

Sava Data & Image Using NSUserDefaults

To save data NSString *savestring = text1.text; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:savestring forKey:@”savedstring”]; [defaults synchronize]; To load data NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *loadstring = [defaults objectForKey:@”savedstring”]; [label1 setText:loadstring]; To save image using NSUserDefaults, In ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIImageView *containedimage; IBOutlet UIImageView *newimage; } – (IBAction)load:(id)sender; – (IBAction)savebutton:(id)sender; @end In ViewController.m #import “ViewController.h” @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a…

Continue reading »