Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

coolbeans777

macrumors newbie
Original poster
Mar 18, 2011
4
0
Do you think it is a bad idea to completely defy Objective-C getter conventions by defining a getter method such as origin as getOrigin instead? I really don't like the idea of just writing "origin" for a getter method because it makes it look too much like an instance/class variable and I feel like it makes much more sense to do it my way.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Use properties, then you don't need to write an accessor yourself, @synthesize will handle it. If you must you can then write a getX method that uses the accessor (or I guess accesses the property directly). If you choose only to implement getX accessors you won't be key-value compliant, you won't be able to use dot-property syntax, and other people using your class will be confused. Why do you want to type more and be specifically unusual compared to existing code? You're going to have to be used to it to use other frameworks anyway, you may as well just do it "right" in your own code.

-Lee
 

firewood

macrumors G3
Jul 29, 2003
8,108
1,345
Silicon Valley
You can define your own property accessor names by using the getter and setter attributes of any property.

Code:
@property (getter=gimmeThatFoo, setter=stuffThisIntoFooNow:) fooType foo;
 

coolbeans777

macrumors newbie
Original poster
Mar 18, 2011
4
0
Use properties, then you don't need to write an accessor yourself, @synthesize will handle it. If you must you can then write a getX method that uses the accessor (or I guess accesses the property directly). If you choose only to implement getX accessors you won't be key-value compliant, you won't be able to use dot-property syntax, and other people using your class will be confused. Why do you want to type more and be specifically unusual compared to existing code? You're going to have to be used to it to use other frameworks anyway, you may as well just do it "right" in your own code.

-Lee

That's true.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Stay with Obj-C conventions. "get" in a method name has a specific and very different meaning in Obj-C than it does in other languages.
 

coolbeans777

macrumors newbie
Original poster
Mar 18, 2011
4
0
Stay with Obj-C conventions. "get" in a method name has a specific and very different meaning in Obj-C than it does in other languages.

Didn't know that, I guess I'll definitely stay with Objective-C conventions:apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.