Confusing with the workthrough


Hi, being new to programming I’m really trying (and seem to be mostly failing) to retain all the information being given so far. I’d really appreciate it if someone could explain a section of code for me.

@property (nonatomic, copy) NSArray *assets; -(double)yearsOfEmployment; -(void)addAssets:(BNRAsset *)a; -(unsigned int)valueOfAssets;
For this section, I don’t understand the -(void)addAssets:(BNRAsset *)a; part. It’s the example from the book. I’m not sure what it’s telling me so I can’t learn when to use it. Any help would be really appreciated.


[quote]@property (nonatomic, copy) NSArray *assets; -(double)yearsOfEmployment; -(void)addAssets:(BNRAsset *)a; -(unsigned int)valueOfAssets;
…I don’t understand the -(void)addAssets:(BNRAsset *)a; part…[/quote]
That line declares a method which takes a single argument as input, an instance of BNRAsset, and returns void (that is, nothing) to the caller:

- (void)addAssets:(BNRAsset *)a;

As do the lines above and below it:

- (double)yearsOfEmployment;
- (unsigned int)valueOfAssets;

However, these two methods do not take any arguments, but they return values to the caller. Their declarations look simpler than that of addAssets:.

This is the way it is: that is, the way those declarations are written is required by the syntax of the Objective-C language. (The syntax is a set of rules which programmers must strictly obey in order to communicate their intentions to the compiler.)

All programming languages, just like natural languages (for example, English), have their own grammars (syntax + semantics) which the programmers must strictly follow.


Thanks so much, that really makes so much more sense!