Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A couple things. </p> <ol> <li><p>Your createFruit method is wrong. It should be:</p> <pre>+ (Fruit *) createFruit { //autorelease, because the Create Rule only applies to CoreFoundation functions return [[[Fruit alloc] init] autorelease]; }</pre></li> <li><p>Instance variables are <code>@protected</code> by default. That means they can be directly accessed by the class and any subclasses. You can make it <code>@protected</code>, <code>@private</code>, <code>@public</code>, and <a href="https://stackoverflow.com/questions/772600/what-does-the-package-directive-do-in-objective-c"><code>@package</code></a>. You do so like this:</p> <pre>@interface Apple : Fruit { @private int iSeed } ... @end</pre></li> <li><p>If you want an instance variable to be readonly, then don't declare it as <code>@public</code>, but make a getter for it. For example:</p> <pre>- (int) iSeeds { return iSeeds; }</pre></li> <li><p>However, since the instance variable is readonly, you can't set it externally. The way around this is to give the Apple a iSeed value during initialization:</p> <pre>- (id) initWithSeeds:(int)aniSeedValue { if (self = [super init]) { iSeed = aniSeedValue; } return self; }</pre> <p>Then make your <code>createAppleWithColor:(int)iSeeds</code> method like:</p> <pre>+ (Fruit *) createAppleWithColor:(int)iSeeds { return [[[Apple alloc] initWithSeeds:iSeeds] autorelease]; }</pre></li> <li><p>Finally, you should read the <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CodingGuidelines/CodingGuidelines.html" rel="nofollow noreferrer">Naming Conventions guide</a> and the <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html" rel="nofollow noreferrer">Memory Management guide</a>.</p></li> </ol>
 

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