次のインターフェースが与えられた場合:
@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 =@{
[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]
allValues メソッドを使用する場所をコメントアウトすると、コードは正常に機能します。リテラルのバグ、または私のせいですか?