Faisal Ahmad
Faisal Ahmad

Reputation: 11

How to create and use same objects in view controller methods?

Hi am a experienced Java programmer.I've just stepped into learning Objective-C and XCode.I am unable to understand a very basic but important thing which is not letting me progress any further.

I want to create objects of classes defined by me and then access and use those objects in the View Controller methods of different Views in the Storyboard. I don't know where and how to create the objects so they could be accessed in any View.In Java I can do everything in main but the structure of Objective C is confusing me.

For example I have a class

@interface list : NSObject
{
NSMutableArray* ary;
}
@end

I want to create objects of this class and use them those objects in the methods of different View Controllers. How can I do so? Please can somebody just give me a to the point answer about where to create the objects so they could become accessible in View Controller methods. I have seen far to complex answers but not basic ones PS: I'm using XCode 4.4

Upvotes: 1

Views: 1051

Answers (1)

user427969
user427969

Reputation: 3896

I think you should read some books or tutorials.

Some books:

For tutorial - just google it - one of them:


Say, you have mainViewController class where you want to use your list class then you can do something as follows:

// mainViewController.h

#import "list.h"

@interface mainViewController

@property (nonatomic, strong) list *objList;

@end


// mainViewController.m

@implementation mainViewController

@synthesize objList = _objList;

- (void) viewDidLoad {
    self.objList = [[list alloc] init];
}

- (void) someMethod {
    self.objList.ary = ...;
}

@end

Upvotes: 1

Related Questions