0

You can access class methods of many Apple classes as properties. Example:

[UIDevice currentDevice];
UIDevice.currentDevice;

Those are the same and both work. How can one implement the same in their classes?

james_womack
  • 10,028
  • 6
  • 55
  • 74

2 Answers2

2

You don't need to do something special for the same, it's by default nature but it's always preferable for beginners not to use dot syntax. A proper discussion is in the post below Dot notation vs. message notation for declared properties

Community
  • 1
  • 1
LebRon
  • 755
  • 4
  • 24
  • In editors other than Xcode, that doesn't work. You'll get the error: request for member ‘methodName’ in something not a structure or union. That's why I thought otherwise. Thank you. – james_womack Mar 20 '12 at 10:53
  • I was aware that properties and dot syntax are for accessing state, which is why (in addition to the fact it doesn't work in CodeRunner) I had forgotten that methods could be accessed that way. – james_womack Mar 20 '12 at 11:00
1

You don't need to do anything. You can use "dot notation" on any method, whether it was declared by a @property or or by a normal method declaration. That's true for both objects and classes.

Kurt Revis
  • 27,695
  • 5
  • 68
  • 74
  • In editors other than Xcode, that doesn't work. You'll get the error: request for member ‘methodName’ in something not a structure or union. That's why I thought otherwise. Thank you. – james_womack Mar 20 '12 at 10:53
  • By "editors other than Xcode" you mean ["CodeRunner"](http://krillapps.com/coderunner/), then? Sounds like a bug in CodeRunner. – Kurt Revis Mar 20 '12 at 16:32
  • +1 Yes, I knew I wouldn't get away with that poor phrasing :) – james_womack Mar 21 '12 at 23:18