从我读过的内容中NSMutableArray添加了对象。
如何Student从给定位置打印对象变量而不将对象转换为Student.
我正在寻找类似ArrayList<Student>Java 的东西,所以我可以轻松地打印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]);