Objective-C를 배우고 있는데, 수업 중 하나 인 Employee 클래스와 Employee 클래스가있는 Superclass Person 클래스를 만듭니다. Asset 클래스는 Employee 클래스가 소유하고 있습니다. 클래스, 그 인스턴스 기능을 테스트하기 위해, 나는 다음과 같은 코드Objective-C 객체를 만드는 데 가장 좋은 프로그래밍 방법은 무엇입니까?
int main(int argc, const char *argv[]){
@autoreleasepool{
NSMutableArray *employees = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++){
Employee *person = [[Employee alloc]init];
[person setWeightInKilos:90 + i];
[person setHeightInMeters:1.8 - i/10.00];
[person setEmployeeID:i];
[employees addObject:person];
}
.../*code continues from here, to assign [person]
's at random indexes in *employees, instances of the Asset class */
}
}
을 썼다 궁금 차례로과 같이, 다른 메소드를 호출 한 방법으로 setting
[person]
의 장점 또는 단점은 무엇입니까 :
main.m:
....
for (int i = 0; i < 10; i++){
Employee *person = [[Employee alloc]init];
[person setWeightInKilos:90 + i withAHeightOf:1.8 - i/10.00 andId:i];
[employees addObject:person];
}
....
감사합니다.
개체를 만든 즉시 해당 정보를 설정해야하는 경우 이니셜 라이저를 매개 변수로 사용하십시오. –