0

What is wrong with this I am getting 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];

Formatted:

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
    still to be discussed with our designer.", 1, @"Less1", @"LibLess1Image.jpg", 0, 1, you need to give all objects between @"" and you should not declare NSDictionary inside NSArray Commented Apr 8, 2012 at 13:08
  • Thank you so much Sree Charan I am still learning objC Commented Apr 8, 2012 at 13:14
  • Yes this is just a test code. Commented Apr 8, 2012 at 13:14
  • In addition to what Sree Charan said, you also seem to have your keys and objects swapped. (That is, I assume something like @"Title" would be a key.) Commented Apr 8, 2012 at 13:21

2 Answers 2

5

NSArray objects can only contain objects. Each integer need to be converted to a NSNumber.

In particular the second embedded NSArray contains

0, 1

which should be

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

Or made strings:

@"0", @"1"

Please break out the embedded NSArrays and NSDictionary into separate statements for readability. More clearly written code would probably make it easier to find errors.

Example:

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];

I make a guess at better var names. Also better formatting is possible for the arrays. Notice the elimination of the duplicate NSArray lessonKeys.

Still this might be better in a plist file that is read. That would allow making changes and adding lessons without requiring code changes.

Sign up to request clarification or add additional context in comments.

1 Comment

a4arpan please implement what zaph has answered and accept this answer this will help you , i am about to post this answer :)
2

Those literal numbers are the problem. Collections must hold NSObjects. If you replace them with NSNumbers (and make sure the counts of keys and values match) it should be okay.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.