diff --git a/YoungFighterCourse/AppDelegate.m b/YoungFighterCourse/AppDelegate.m index 0a42d4efee617d214d9f10d8c0dd7959f2c49c02..372bab9ce513e5c8b7833c167962db2fe6929780 100644 --- a/YoungFighterCourse/AppDelegate.m +++ b/YoungFighterCourse/AppDelegate.m @@ -27,7 +27,7 @@ NSLog(@"Avg salary for 1 employee %f", avgSalary); NSLog(@"Adding new employee"); - [organization addEmployeeWithName:@"NeDenis"]; + [organization addEmployeeWithName:@"Alexey Bondarchuk"]; float avgSalaryForTwo = [organization calculateAverageSalary]; NSLog(@"Avg salary for 2 employee %f", avgSalaryForTwo); @@ -43,6 +43,11 @@ for (Employee *eployee in employeesWithTolerance) { NSLog(@"%@, salary = %i", eployee.fullName, eployee.salary); } + NSLog(@"Before removing employee amout = %i", organization.employeeAmount); + NSLog(@"Delete employee %@", em.fullName); + [organization removeEmployee:em]; + NSLog(@"After removing employee amout = %i", organization.employeeAmount); + } diff --git a/YoungFighterCourse/Organization.h b/YoungFighterCourse/Organization.h index 239499bbe2804a0703b64f7e9416d1d13e582733..68570d8568820f9598e07ad06176e4636f375d76 100644 --- a/YoungFighterCourse/Organization.h +++ b/YoungFighterCourse/Organization.h @@ -14,6 +14,8 @@ NSArray<Employee*> *employees; } +@property (readonly, getter=employeeCount) int employeeAmount; + @property (nonatomic, readwrite) NSString* name; -(id)initWithName:(NSString*)orgName; @@ -28,6 +30,10 @@ -(NSArray<Employee*>*) employeesWithSalary:(int)salary Tolerance:(int)tolerance; +-(void) removeEmployee:(Employee*)employee; + +-(int) employeeCount; + @end diff --git a/YoungFighterCourse/Organization.m b/YoungFighterCourse/Organization.m index 178d2a1a0a215059b8a95a848f180172c0e8d4b9..e1ecb8a808bbb1b7df827c54c4b5471fa946046a 100644 --- a/YoungFighterCourse/Organization.m +++ b/YoungFighterCourse/Organization.m @@ -69,4 +69,14 @@ return newEmployees; } +-(void) removeEmployee:(Employee*)employee { + NSMutableArray *buffer = [NSMutableArray arrayWithArray:employees]; + [buffer removeObject: employee]; + employees = buffer.copy; +} + +-(int) employeeCount { + return employees.count; +} + @end