NSObject에서 상속 한 클래스가 있습니다. NSMutableArray를 사용하여 자식 객체 (예 : Person 객체를 저장하기 위해 NSMutableArray * 항목을 사용하는 사람들. 항목에 NSFastEnumerator를 구현하려면 어떻게해야합니까?사용자 정의 클래스에 NSFastEnumeration 구현
나는 시도 다음 그러나 그것은 잘못되었습니다
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
{
if(state->state == 0)
{
state->mutationsPtr = (unsigned long *)self;
state->itemsPtr = items;
state->state = [items count];
return count;
}
else
return 0;
}
무엇입니까 당신이하려고? [array count]를 사용하면 어레이의 특정 유형의 객체 수를 얻으려는 경우 (배열의 id 객체) <= 빠른 열거 형인 –
인스턴스 내 애플 리케이션 클래스 내 인스턴스에서이 일을 할 수 있다고 가정 해 봅시다 : for (Person * p in People) { NSLog (p); } – user593733