2012-07-12 9 views
1

인터페이스 다음 감안할 때 :있는 NSDictionary 리터럴, 모든 값 방법에 예외

@interface DetailViewController() 
@property (nonatomic, strong) NSDictionary *contentTypeToString; 
@property (nonatomic, strong) NSDictionary *contentTypeToContent; 
@property (nonatomic, strong) NSArray *contentDestcriptors; 
@property (nonatomic, strong) NSArray *content; 
@end 

그리고 다음과 같은 방법

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    //dumb data 

    self.contentTypeToString [email protected]{ 
    [NSNumber numberWithInt:ContextTypePlace] : @"Place", 
    [NSNumber numberWithInt:ContextTypeDate] : @"Date", 
    [NSNumber numberWithInt:ContextTypeTime] : @"Time", 
    [NSNumber numberWithInt:ContextTypeWeather] : @"Weather", 
    [NSNumber numberWithInt:ContextTypeSeason] : @"Season", 
    [NSNumber numberWithInt:ContextTypeTimeOfDay] : @"Time of Day", 
    [NSNumber numberWithInt:ContextTypePlace] : @"Place", 
    }; 

    self.contentTypeToContent = @{ 
    [NSNumber numberWithInt:ContextTypePlace] : @"Dublin", 
    [NSNumber numberWithInt:ContextTypeDate] : @"21.12.2012", 
    [NSNumber numberWithInt:ContextTypeTime] : @"21:32", 
    [NSNumber numberWithInt:ContextTypeWeather] : @"Cloudy", 
    [NSNumber numberWithInt:ContextTypeSeason] : @"Winter", 
    [NSNumber numberWithInt:ContextTypeTimeOfDay] : @"Evening", 
    [NSNumber numberWithInt:ContextTypePerson] : @"John, Ann", 
    }; 

    self.contentDestcriptors = [self.contentTypeToString allValues]; 
    self.content = [self.contentTypeToContent allValues]; 
} 

내가 얻을 : 응용 프로그램을 종료

인해 캐치되지 않는 예외 NSRangeException 이유에 : *** -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 5]

Tf 나는 e 어디에서 allValues ​​metod를 사용하는지, 코드는 잘 동작합니다. 리터럴 버그, 또는 내 잘못? `: [ContextTypePlace의 NSNumber numberWithInt]

+2

가 가다가 대신'의 ContextTypePlace' @'사용할 수있는 두 번 6 개 항목으로 사전을 만들 것

ContextTypePlace 지정 –

+0

예외가 발생하면 스택 추적을 게시 할 수 있습니까? – joerick

+0

실제 @ (enum-value)뿐만 아니라 @ enum-value – foFox

답변

2

당신은 당신이 리터럴 객체를 사용하는 경우되지 7.

+0

그래, 맞아, 복사 및 붙여 넣기 감사의 결과! – foFox

+0

여전히 'allValues'를 파기해서는 안됩니다. – fzwo

+2

배열이 ** 6 일 때 배열에 7 개의 값이 있다고 가정하면 ** ** 배열에 액세스 할 때 충돌이 발생한다고 생각합니다. –