2011-11-06 2 views
2

이 질문/응답 덕분에 Automatic Reference Counting: Error with fast enumeration은 나를 미치게 만드는 부분을 해결했습니다.NSDictionary에서 빠른 열거 형 오류가 발생했습니다.

그러나, 나는 여전히 " '있는 NSDictionary * __ 강한 ' '__unsafe_unretained ID'변경 포인터의/방출 특성을 유지하기 위해 할당 "오류를 얻고있다. 나는 ARC 프로그래밍 가이드와 포인터 변환과 관련된 부분을 읽었지만, 불행히도 아직 충분한 C 프로그래머가 아닙니다.

주석의 코드 행을 참조하십시오. 어떤 도움이라도 대단히 감사하겠습니다. 미리 감사드립니다. .H 파일

@interface BWDB : NSObject <NSFastEnumeration> { 
    NSDictionary * enumRows[1]; 
} 
+2

'id'는 이미 포인터입니다. –

답변

2

이 그것을 해결됩니다에서이 선언

- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *)state 
           objects: (id __unsafe_unretained *)buffer 
           count: (NSUInteger)bufferSize 
{ 
    if (*enumRows = [self getPreparedRow]) { 
     state->itemsPtr = enumRows; // Assigning 'NSDictionnary *__strong *' to '__unsafe_unretained id*' changes retain/release properties of pointer 
     state->state = 0; 
     state->mutationsPtr = &state->extra[0]; // was state->mutationsPtr = (unsigned long *) self; before 
     return 1; 
    } else { 
     return 0; 
    } 
} 

.

@interface BWDB : NSObject <NSFastEnumeration> { 
    __unsafe_unretained NSDictionary *enumRows[1]; 
} 

게시 한 코드에 따르면이 코드는 매번 확인하기 전에 할당해야하므로 완벽하게 안전해야합니다. 사실 인스턴스 변수를 전혀 만들 필요가 없습니다. 내가 NSDictionaries의 포인터 [] 타입의 배열을 가지고있는 많은 가치가없는 점에 유의해야한다

{ 
    __unsafe_unretained NSDictionary *enumRows[1]; 
    if ((*enumRows = [self getPreparedRow])) { 
     state->itemsPtr = NULL; 
     state->itemsPtr = enumRows; 
     state->state = 0; 
     state->mutationsPtr = &state->extra[0]; 
     return 1; 
    } else { 
     return 0; 
    } 
} 

:

당신은 뭔가를 할 수 있습니다. 단순히 NSArray를 사용하여 NSDictionaries를 유지하는 것이 훨씬 더 유리할 것입니다.

+0

대단히 감사합니다. 감사합니다. –

+0

@brad 기꺼이 도와주세요. 해답이 문제를 해결했다면 받아 들여야합니다. – NJones