4. Write a “Metropolis” class. It should contain the following:
Variable:
array of 10 cities.
Instance method:
createCity:atIndex:withPopulation: (single method) which creates a city with first parameter being a name at index (from the second parameter) and sets its population to that of third parameter. So, you should be able to do this:
[myMetropolis createCity: @”Almaty” atIndex: 2 withPopulation: 1500000]
Не очень понимаю как это сделать. Вот мои наброски:
@interface Metropolis:NSObject{
NSMutableArray * newArray;
}
-(void)createMassive;
-(void)createCity:(NSString *)nameSeccond andindex: (int) atIndex andpopulation: (int) withPopulation;
@end
////////////////////////////////
@implementation Metropolis
-(void)createMassive{
newArray = [[NSMutableArray alloc]init];
}
-(void)createCity:(NSString *)nameSeccond andindex: (int) atIndex andpopulation: (int) withPopulation{
[newArray initWithObjects:nameSeccond, withPopulation,nil];
}
@end
Metropolis * mt = [[Metropolis alloc]init];
[mt createMassive];
[mt createCity:@"Minks" andindex:1 andpopulation:1600000];
NSLog(@"massiv%@", [mt newarray]);
Тут однозначно что-то не так) Объясните пожалуйста что делаю не так?