Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You cannot get the address of something returned by a function (or method). You need to get the address of the <code>color</code> ivar directly (i.e. <code>&amp;color</code>). In your case though, I recommend using the approach you proposed yourself (<code>id tempCol = self.color; [NSValue value:&amp;tempCol];</code>).</p> <hr> <p>Note that a method is invoked when using dot notation.</p> <pre><code>self.color // is equal to [self color] </code></pre> <p><code>&amp;([self color])</code> is also impossible because <code>&amp;</code> is resolved at compile-time, not at runtime. The return value of <code>[self color]</code> and <code>self.color</code> (which are equal) aren't yet known at compile-time (even when using <code>@synthesize</code>, since you can change a method's implementation in Objective-C at runtime (e.g. with method swizzling or using categories)).</p> <hr> <p>It seems that you don't fully understand what <code>@synthesize</code> does, so I'll explain. :)</p> <p>Basically what <code>@synthesize</code> does is this: the compiler generates methods and their implementations from the given property names.</p> <p>For example, this property:</p> <pre><code>@property(nonatomic, retain) NSColor *color; </code></pre> <p>Together with this synthesization:</p> <pre><code>@synthesize color; </code></pre> <p>Will insert this code for you in the <code>@implementation</code>:</p> <pre><code>- (NSColor *)color { return color; } - (void)setColor:(NSColor *)newColor { if (color == newColor) { return; } NSColor *theOldColor = color; color = [newColor retain]; [theOldColor release]; } </code></pre> <hr> <p>When you like to use your own setter or getter, you simply define these in the <code>@implementation</code> by using the same method names. You could, for example, return a default color if none is set yet:</p> <pre><code>- (NSColor *)color { if (color) { return color; } return [NSColor whiteColor]; } </code></pre> <p>Now the compiler will generate the setter, but not the getter: it will use the getter you provided, you can still use it with <code>self.color</code>.</p> <hr> <p>You may want to take a look at <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html" rel="nofollow">Apple's guide on properties</a>.</p>
 

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