Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, this is all sorts of messed up, so let's just step back a little bit. An array is an indexed set of objects. An index is a non-negative integer that represents the location of an object. Each object is accessible in the array by an index. You can't do <code>[[thisYear courses] scoreCategories]</code> and expect anything to work, because you haven't actually provided an index to the object in the array. You could do something like <code>[[thisYear courses] objectAtIndex:0]</code>, which would return the first element in the array. You could also do <code>[[thisYear courses] objectAtIndex:1]</code>, which would return the second element in the array.</p> <p>Whenever you insert an element into an <code>NSMutableArray</code>, it inserts it as the last object in the array. For instance, if the <code>NSMutableArray</code> you're inserting your object into doesn't have any elements contained within it, the index of the element you're inserting is 0. If it have 1 element in it, then the index of the element you're inserting would have an index of 1. </p> <p>The code you're probably looking for is this:</p> <pre><code>NSMutableArray *scoreCategories = [NSMutableArray array]; [scoreCategories addObject:myNewObj]; [[thisYear courses] addObject:scoreCategories]; </code></pre> <p>However, there are a lot of other problems with doing things this way. Before proceeding any further, I'd recommend you spend some time with a good Objective-C <a href="http://rads.stackoverflow.com/amzn/click/1430218150" rel="nofollow">book</a>. </p> <p><strong>Update</strong></p> <p>Okay, let's take another look at this. This is pretty tough without the context in which this code appears, but we'll try anyway.</p> <pre><code>dGradeURin *thisYear = [[[dGradeURin alloc] init] autorelease]; thisYear.howManyTerms = [NSNumber numberWithInteger:4]; thisYear.gradeURin = @"Freshman"; NSMutableArray *courses = [NSMutableArray array]; //set up a temporary course dCourse *temporaryCourse = [[[dCourse alloc] init] autorelease]; temporaryCourse.cName = @"Computer Science"; temporaryCourse.school = @"Freedom High"; temporaryCourse.scoreCategories = [NSMutableArray array]; dScoringCategory *temporaryScoringCategory = [[[dScoringCategory alloc] init] autorelease]; temporaryScoringCategory.name = @"Quizzes"; [temporaryCourse.scoreCategories addObject:temporaryScoringCategory]; [courses addObject: temporaryCourse]; thisYear.courses = courses; </code></pre> <p>This first line creates an autoreleased object. That means that at some point, the memory this object is taken up will be freed for use somewhere else. If you don't free the memory of an object, then it will keep taking up memory, whether you ever use it or not. For more about this (and you <em>really</em> need to understand it to use Objective-C), check out <a href="http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html" rel="nofollow">Apple's documentation</a>.</p> <p>A couple of other things. If this is homework, and it looks like it might be from the content, then <strong>be sure you tag it as homework</strong>. I don't mind helping you here because it looks like most of your problems are syntactic, but don't forget next time.</p> <p>Second, I don't know where you got those classes, but assuming you're using the interfaces correctly, they appear to be poorly designed. There's a lot of understanding required to make things work well rather than just work. I'd still recommend reading that book I linked above if you really want to learn this stuff.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload