Necessary changes in .main when moving to @synthesize


Hey everyone, I am following the book, enjoying it a lot, well done.

I’m here in chapt. 17, changing things over from standard wordy accessor method declaration to properties and @synthesize syntax. (page 105) Everything is now nice and concise, it all makes sense, looks great, but I get red fail flags in my main code… Why? I couldn’t figure it out! I eventually changed my ivar setting code in the .main to dot notation and the code worked again. This was odd to me since apparently dot notation is not what A.H. wants us to use. There must be another way…?

Before reading further, does anyone know what my problem was?

So after a bunch of web searching I find a tiny tidbit of knowledge on some blog…
“When using auto synthesized accessor methods, Obj-C needs you need to capitalize the first letter of the variable”.

So my original code below was broken:
[persOne setheightInMeters:1.77];

But works fine after changing it to this:
[persOne setHeightInMeters:1.77];

Was this mentioned in the book? I have no object oriented experience before this, maybe it makes sense and is straight forward for some reason?? Or is it just one of those Obj-C things?



i had no programming experience at all before reading this book and from what i understand is this so i could be wrong but as far as i know.

@interface Person: NSObject

@property float heightInMeters; ////the accessor method for property is written like so, getter is always the name of the property so (heightInMeters) the setter is always start with (set) but then the word after that is always capitalized so it would be Height not height so the setter is setHeight. you can also write your own getter/setter names.

look on page 103 and you shall see this


Anyone else fall into this trap? No comments about why Obj-C wants you to capitalize the Ivar name when using @synthesize accessor methods?



im guessing its how the syntax is with objects you always capitalize the every word after the first (if you have more than one word) So heightInMeters not heightinmeters so since for the setter the word set is the first word everything else is CAPiTalize its not a trap -__- just the way it is