내가 읽은 것 NSMutableArray
는 개체를 추가합니다.NSMutableArray에서 객체 변수를 인쇄하는 방법은 무엇입니까?
개체를 Student
으로 캐스팅하지 않고 주어진 위치에서 Student
개체 변수를 어떻게 인쇄 할 수 있습니까?
나는 ArrayList<Student>
같은 것을 찾고 있는데, 쉽게 ArrayList.get(i).getName
, ArrayList.get(i).getPrice
을 인쇄 할 수 있습니다.
StudentRepository* myStudentRepo = [[StudentRepository alloc]init];
Student* myStudent = [[Student alloc]init];
myStudent.name = @"John";
// add a Student to the NSMutableArray
[myStudentRepo.studentRepository addObject:myStudent];
NSLog(@"Value: %@", myStudentRepo.studentRepository);
for(Student* myStudentItem in myStudentRepo.studentRepository)
{
NSLog(@"Value: %@", myStudentItem.name);
}
// print the Student from a given position
NSLog(@"Value: %@", [(Student*)[myStudentRepo.studentRepository objectAtIndex:0] name]);
감사합니다! – Mythul