Hi guys,
Been playing around with Xcode for about 2weeks now, and reading about MVC a bit. I have a problem trying to connect the Model to the Controller because I find it hard to get my head around arrays. I can handle simple arrays when i programmed some in Java but I'm quiet intimidated by the Obj-C NSArrays i see.
If somebody would be so kind to show me some simple calls on an array of objects i would be eternally grateful.
My model :
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *name;
NSNumber *age;
}
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSNumber *age;
@end
Person.m
#import "Person.h"
@implementation Person
@synthesize name;
@synthesize age;
@end
I've kept if very simple while I try and learn.
Now my Controller class. What i want to do is create an array of 40 'Person' objects. But i don't know the correct way to put that in code in Obj C.
Controller.h
#import <Foundation/Foundation.h>
@class Person;
@interface Controller : NSObject
{
Person *person;
}
@property(nonatomic, retain) Person *person;
-(void) doSomeWork;
@end
Controller.m
#import "Controller.h"
#import "Person.h"
@implementation Controller
@synthesize person;
-(IBAction)doSomeWork
{
// I guess here is where i should create my array of 40 person objects
}
@end
My problem is in how to declare the array of person objects of size 40. And then how to access the array to read and write to it.
Thanks in advance for reading my post.
-Code