So i sat down and redid this and wanted to post an update. This all seems to be working as planned now:
Main:
Employee.h
Employee.M
Asset.h:
Asset.m:
Besides everything appearing to be working now, how does it look? I know utilizing data encapsulation was recommended a few times so i wanted to look into that more. Would you hide any of my code in main in their respective classes?
I was thinking if i did an Employee method something along the lines of
(Employee*) configEmployee
Would let me alloc/init the employee, along with set the employeeID, then return that employee to main where configAsset would do similar. They woudl then be connected in main.
However i couldn't figure out how to actually return an employee instance from an Employee method, or if that would even be recommended over my code above?
Thanks again! you all have be such a help!
Main:
Code:
#import <Foundation/Foundation.h>
#import "Asset.h"
#import "Employee.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *listOfEmployee = [[NSMutableArray alloc] init];
int employeeCount = 0;
for (employeeCount = 0; employeeCount < 10; employeeCount ++)
{
//create asset and employee isntances
Employee *employee = [[Employee alloc] init];
Asset *asset = [[Asset alloc] init];
//set employeeID and asset number to ia
employee.employeeID = employeeCount;
asset.assetNumber = employeeCount;
employee.employeeAsset = asset;
[listOfEmployee addObject:employee];
}
//print listOfEmployee
NSLog(@" %@", listOfEmployee);
}
return 0;
}
Employee.h
Code:
#import <Foundation/Foundation.h>
#import "Asset.h"
@interface Employee : NSObject
@property int employeeID;
@property Asset *employeeAsset;
@end
Employee.M
Code:
#import "Employee.h"
#import "Asset.h"
@implementation Employee
@synthesize employeeID;
@synthesize employeeAsset;
-(NSString *) description
{
return [NSString stringWithFormat:@"Employee ID:%i with %@", employeeID,employeeAsset];
}
@end
Asset.h:
Code:
#import <Foundation/Foundation.h>
@interface Asset : NSObject
@property NSString *assetLabel;
@property int assetNumber;
@end
Asset.m:
Code:
#import "Asset.h"
@implementation Asset
@synthesize assetLabel;
@synthesize assetNumber;
-(NSString *) description
{
return [NSString stringWithFormat:@"Laptop Number:%i",assetNumber];
}
@end
Besides everything appearing to be working now, how does it look? I know utilizing data encapsulation was recommended a few times so i wanted to look into that more. Would you hide any of my code in main in their respective classes?
I was thinking if i did an Employee method something along the lines of
(Employee*) configEmployee
Would let me alloc/init the employee, along with set the employeeID, then return that employee to main where configAsset would do similar. They woudl then be connected in main.
However i couldn't figure out how to actually return an employee instance from an Employee method, or if that would even be recommended over my code above?
Thanks again! you all have be such a help!