2012-04-08 2 views
0

Was mit dieser falsch ist, ich bin immer EXEC_BADObjective C Array init EXEC_BAD werfen

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

Formatiert:

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

noch mit unserem Designer zu diskutieren. ", 1, @" Less1 ", @" LibLess1Image.jpg ", 0, 1, müssen Sie alle Objekte zwischen @" "geben und NSDictionary in NSArray – Charan

+0

nicht deklarieren Vielen Dank Sree Charan Ich lerne immer noch objC – a4arpan

+0

Ja, das ist nur ein Testcode – a4arpan

Antwort

5

NSArray Objekte können nur Objekte enthalten. Jede ganze Zahl muss in eine NSNumber konvertiert werden.

insbesondere im zweiten NSArray eingebettet enthält

0, 1 

die

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

Oder gemacht Strings sein sollte:

@"0", @"1" 

Bitte brechen die eingebetteten NSArray s und NSDictionary in getrennte Aussagen zur Lesbarkeit. Ein klarer geschriebener Code würde es wahrscheinlich leichter machen, Fehler zu finden.

Beispiel:

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

Ich mache eine Vermutung zu besseren var Namen. Auch eine bessere Formatierung ist für die Arrays möglich. Beachten Sie die Beseitigung des Duplikats NSArray LessonKeys.

Noch könnte dies in einer PLIST-Datei, die gelesen wird, besser sein. Das würde es ermöglichen, Änderungen vorzunehmen und Lektionen hinzuzufügen, ohne Codeänderungen zu erfordern.

+0

a4arpan bitte implementieren, was Zaph beantwortet hat und diese Antwort akzeptieren das wird dir helfen, ich bin dabei, diese Antwort zu posten :) – Charan

2

Diese wörtliche Zahlen sind das Problem. Sammlungen müssen NSObjects enthalten. Wenn Sie sie durch NSNumbers ersetzen (und sicherstellen, dass die Anzahl der Schlüssel und Werte übereinstimmt), sollte es in Ordnung sein.

Verwandte Themen