Evening,
So I am trying to teach myself Objective-C and have a question. One particular area of toughness so far to me appears to be this:
Lets say NSObject has 2 classes: Employee & Asset
I want to create 10 instances of each, have each instance number (Employee ID and Asset Number), and then link the two together in an array.
This is what my scrap work looks like so far:
So im pretty sure everything looks good right up to the end of the asset section. I am not sure how i would go about assigning the asset (i) to the employee from the array employeeList (at index i)
My .h/.m files for the 2 classes are pretty bare at the moment, trying to keep this as basic as possible up until i got the the "assigning" portion to help myself better understand this concept:
@interface Employee : NSObject
@property int employeeID;
@implementation Employee
@synthesize employeeID;
@interface Asset : NSObject
@property NSString *assetLable;
@implementation Asset
@synthesize assetLable;
Thank you!!!
(BTW using Big Nerd Ranch Guide, for what its worth)
So I am trying to teach myself Objective-C and have a question. One particular area of toughness so far to me appears to be this:
Lets say NSObject has 2 classes: Employee & Asset
I want to create 10 instances of each, have each instance number (Employee ID and Asset Number), and then link the two together in an array.
This is what my scrap work looks like so far:
Code:
main.m:
int main(int argc, const char * argv[])
{
@autoreleasepool {
//create employee list array
NSMutableArray *employeeList = [[NSMutableArray alloc] init];
//create 10 employees, assign their employee ID, and add to employee list array
for (int i = 1; i <11; i++)
{
Employee *employeeInstance = [[Employee alloc] init];
[employeeInstance setEmployeeID:i];
[employeeList addObject:employeeInstance];
}
//create 10 assets (laptops)
for (int i =1; i<11; i++)
{
Asset *assetInstance = [[Asset alloc] init];
NSString *assetNumber =[NSString stringWithFormat:@"Laptop:%i", i];
[assetInstance setAssetLable:assetNumber];
//find employee ID number that matches asset number (i?)
Employee *employeeNumbered = [employeeList objectAtIndex:i];
//assign the asset to the employee
????????????????
So im pretty sure everything looks good right up to the end of the asset section. I am not sure how i would go about assigning the asset (i) to the employee from the array employeeList (at index i)
My .h/.m files for the 2 classes are pretty bare at the moment, trying to keep this as basic as possible up until i got the the "assigning" portion to help myself better understand this concept:
@interface Employee : NSObject
@property int employeeID;
@implementation Employee
@synthesize employeeID;
@interface Asset : NSObject
@property NSString *assetLable;
@implementation Asset
@synthesize assetLable;
Thank you!!!
(BTW using Big Nerd Ranch Guide, for what its worth)
Last edited by a moderator: