0

これの何が問題になっていますかEXEC_BADを取得しています

self.allLessonsArray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects:@"Title", @"Description", @"LessonID", @"LessonSuffix", @"LibraryImage", @"Price", @"IsFree", nil] forKeys: [NSArray arrayWithObjects: @"First Lesson", @"This is a test description of our first lesson, this lesson is just a copy of Sample StoryApp which we will replace with our first Color Lesson for Very Small Kids. Design of that lesson is still to be discussed with our designer.", 1, @"Less1", @"LibLess1Image.jpg", 0, 1, nil]], [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects:@"Title", @"Description", @"LessonID", @"LessonSuffix", @"LibraryImage", @"Price", @"IsFree", nil] forKeys: [NSArray arrayWithObjects: @"Second Lesson", @"I want to give some description to this title but its so time consuming and boring to write. So here i go - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", 2, @"Less2", @"LibLess2Image.png", 0.99, 0, nil]], nil];

フォーマット済み:

self.allLessonsArray = [NSArray arrayWithObjects: 
                        [NSDictionary dictionaryWithObjects: 
                         [NSArray arrayWithObjects:
                          @"Title",
                          @"Description",
                          @"LessonID",
                          @"LessonSuffix",
                          @"LibraryImage",
                          @"Price",
                          @"IsFree",
                          nil] 
                                                    forKeys: 
                         [NSArray arrayWithObjects:
                          @"First Lesson", 
                          @"This is a test description of our first lesson, this lesson is just a copy of Sample StoryApp which we will replace with our first Color Lesson for Very Small Kids. Design of that lesson is still to be discussed with our designer.",
                          1, 
                          @"Less1",
                          @"LibLess1Image.jpg",
                          0, 
                          1, 
                          nil]
                         ], 
                        [NSDictionary dictionaryWithObjects: 
                         [NSArray arrayWithObjects:
                          @"Title", 
                          @"Description", 
                          @"LessonID", 
                          @"LessonSuffix",
                          @"LibraryImage", 
                          @"Price",
                          @"IsFree",
                          nil] 
                                                    forKeys: 
                         [NSArray arrayWithObjects: 
                          @"Second Lesson",
                          @"I want to give some description to this title but its so time consuming and boring to write. So here i go - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", 
                          2, 
                          @"Less2",
                          @"LibLess2Image.png", 
                          0.99,
                          0,
                          nil]
                         ], 
                        nil];
4

2 に答える 2

5

NSArrayオブジェクトには、オブジェクトのみを含めることができます。各整数は に変換する必要がありますNSNumber

特に、2 番目の埋め込みNSArrayには

0, 1

どちらであるべきか

[NSNumber nunberWithInt:0], [NSNumber nunberWithInt:1]

または作成された文字列:

@"0", @"1"

読みやすくするために、埋め込まれたNSArrays とNSDictionaryを別々のステートメントに分割してください。コードをより明確に記述すれば、おそらくエラーを見つけやすくなります。

例:

NSArray *lessonKeys = [NSArray arrayWithObjects:@"Title", @"Description", @"LessonID", @"LessonSuffix", @"LibraryImage", @"Price", @"IsFree", nil];
NSArray *lesson1Values = [NSArray arrayWithObjects: @"First Lesson", @"This is a test description of our first lesson, this lesson is just a copy of Sample StoryApp which we will replace with our first Color Lesson for Very Small Kids. Design of that lesson is still to be discussed with our designer.", [NSNumber numberWithInt:0], @"Less1", @"LibLess1Image.jpg", [NSNumber numberWithInt:0], [NSNumber numberWithInt:1], nil];
NSArray *lesson2Values = [NSArray arrayWithObjects: @"Second Lesson", @"I want to give some description to this title but its so time consuming and boring to write. So here i go - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", [NSNumber numberWithInt:2], @"Less2", @"LibLess2Image.png", [NSNumber numberWithFloat:0.99 ], [NSNumber numberWithInt:0], nil];

NSDictionary *lesson1 = [NSDictionary dictionaryWithObjects: lesson1Values forKeys: lessonKeys];
NSDictionary *lesson2 = [NSDictionary dictionaryWithObjects: lesson2Values forKeys: lessonKeys];

self.allLessonsArray = [NSArray arrayWithObjects: lesson1, lesson2, nil];

より良い変数名を推測します。また、配列のフォーマットを改善することもできます。重複するNSArrayレッスンキーが削除されていることに注意してください。

それでも、読み込まれる plist ファイルではこれの方がよい場合があります。これにより、コードの変更を必要とせずに変更を加えたり、レッスンを追加したりできます。

于 2012-04-08T13:32:12.650 に答える
2

これらの文字通りの数字が問題です。コレクションは NSObjects を保持する必要があります。それらを NSNumbers に置き換えれば (そしてキーと値の数が一致することを確認すれば) 問題ありません。

于 2012-04-08T13:30:30.403 に答える