0

Why would the following:

[object propertyName:propertyValue] cause the above exception in Xcode 4.3 and Lion, but object.propertyName=propertyValue would work just fine? The @property in question is a simple float and I've also used @synthesize.

I'm relatively new to Objective C, but have quite a bit of experience in C#, and have been reading Aaron Hillegass' book on the topic where the two approaches are listed as synonymous, with the [...] being the preferred one.

N_A
  • 19,799
  • 4
  • 52
  • 98
AssenB
  • 11

2 Answers2

3

The setter method is not named the same as the property. You want setPropertyName instead of propertyName when calling it as a method. The getter is still just the property name.

See How to write my own setter for an ivar for a good example.

Community
  • 1
  • 1
N_A
  • 19,799
  • 4
  • 52
  • 98
0

When you use @property and @syntesize to declare variable, system write get and set methods for you. And on this you need use [object setPropertyName:propertyValue]. Also you can use object.propertyName=propertyValue but it's a C programming style.

RomanHouse
  • 2,552
  • 3
  • 23
  • 44
  • Thank you very much! Using the property without the "set" prefix was indeed causing the problem. – AssenB Apr 17 '12 at 05:49