Does anyone know how to add a property in objective c – but that property is also a custom made class?
For instance, I made this class:
@interface Person : NSObject
@property NSString *personName;
@property NSNumber *personAge;
-(id)init;
@end
Where…
@implementation Person
@synthesize personAge, personName;
-(id)init{
self = [super init];
if(self){
self.personAge = [NSNumber numberWithInt:26];
self.personName = @"Jamie";
}
return self;
}
@end
So basically whenever I init & alloc the Person class, it gets setup with personAge as 26 and personName as Jamie.
Now I want to create a bank account class which contains a person property:
@interface BankAccount : NSObject
@property NSNumber *bankAccNumber;
@property (nonatomic) Person *thePerson;
-(id)init;
@end
Where…
@implementation BankAccount
@synthesize thePerson = _thePerson;
@synthesize bankAccNumber;
-(id)init{
self = [super init];
if(self){
bankAccNumber = [NSNumber numberWithInt:999];
}
return self;
}
@end
Now – my issue is this:
1) In the BankAccount class, where do I alloc & init the Person class?
To stay with your example
Of course, in general, you do not want everybody to be 26yo Jamies and have 999$, but I guess you plan to improve on these details later 🙂