Theocacao
Leopard
Design Element
Comment on "A Quick Objective-C 2.0 Tutorial: Part II"
by Scott Stevenson — Oct 11
@charles castille: If I do this, the compiler returns an error saying setNumber is not known. Example code is provided below.

The problem here is just the syntax. To call a method named "-setNumber:", you need to do something like this:

NSNumber* myNumber = [NSNumber numberWithDouble:10.0]; [self setNumber:myNumber];

You only use the equals sign when setting a variable or property value. You could probably also get away with this in Objective-C 2.0:

self.number = [NSNumber numberWithDouble:10.0];

Stylistically, though, you should probably actually define a @property if you're going to do that.
Back to "A Quick Objective-C 2.0 Tutorial: Part II"
Design Element

Copyright © Scott Stevenson 2004-2015