Access your data using class object.
Steps to follow:-
1. Create a NSObject class called DataObject.
2. Declare properties as below...
Write below code in DataObject.h file
@interface DataObject : NSObject
@property (strong, nonatomic) NSString *userId;
@property (strong, nonatomic) NSString *companyName;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *imgStr;
3. Write below code in DataObject.m file
@synthesize userId, companyName, name, imgStr;
4. In AppDelegate.h create an Array..
@property (strong, nonatomic) NSMutableArray *arrModelData;
5. In AppDelegate.m
@synthesize arrModelData;
6. In some class where you filled these properties using your Data (Here I am using Web json data example.. ).
NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:urlData options:0 error:nil];
DataObject *model = [[DataObject alloc]init];
[model setName:[dict valueForKey:@"name"]];
[model setCompanyName:[dict valueForKey:@"companyName"]];
[model setImgStr:[dict valueForKey:@"imgStr"]];
[model setUserId:[dict valueForKey:@"userId"]];
7. And copy model object to arrModelData of AppDelegate
AppDelegate *objAppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.arrModelData addObject: model];
8. Now you can use these properties where you required. Create and initialize DataObject and access all properties then,
DataObject *model = [objAppDelegate.arrModelData objectAtIndex:0 ];
NSLog(@"image string is : %@", model.imgStr);
NSLog(@"Name is : %@", model.name);
NSLog(@"Company Name is : %@", model.companyName);
NSLog(@"UserId is : %@", model.userId);
0 Comment(s)