Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C class method: dot syntax and 'class property'

While programming for iOS I encountered the following scenario:

I have a singleton class with a class method + (Store*)sharedStore. When I want to call an instance method on the singleton object, I can use dot syntax to get that object, i.e. [Store.sharedStore foo].

However, Xcode does not autocomplete 'sharedStore' after typing the dot. On the other hand, [[Store sharedStore] foo] is autocompleted!

Is there such a thing as 'class properties'? If I could turn sharedStore into a readonly property on the class, the dot syntax would gain autocompletion.

More generally speaking, Xcode simply does not autocomplete after dot syntax on anything that isn't a property, even though this is a valid way of calling a (getter) method.

Any solution, workaround, or information is appreciated.

like image 820
Timo Avatar asked Oct 22 '22 20:10

Timo


1 Answers

Currently, as far as class getters go, it appears that we must either:

  • use this syntax in the absence of autocompletion: Store.sharedStore; or
  • use bracket syntax instead: [Store sharedStore].

I have not tried other editors recently (e.g. AppCode). Another editor might autocorrect the dot syntax on class getters.

Opinions vary as to what is correct, logical or readable.

like image 153
Timo Avatar answered Oct 27 '22 21:10

Timo