2

I know how to write selector names in Objective-C like mergeThis:withThat:, but can somebody tell me, how can I reference (e.g. in documentation, text or commit message) that a method belongs to a class and is either an instance method or a class method?

In Ruby I would write String#reverse for instance methods or File::exists?(file_name) for class methods. See this question.

Is there a standardized way or a convention to do so in Objective-C?

Community
  • 1
  • 1
Lukáš Kubánek
  • 946
  • 1
  • 15
  • 27
  • possible duplicate of [Write a method signature including the class name for documentation](http://stackoverflow.com/questions/10421265/write-a-method-signature-including-the-class-name-for-documentation) – jscs Jun 04 '12 at 18:37
  • Sorry, I have searched for it, but I did not found it. – Lukáš Kubánek Jun 04 '12 at 23:08
  • No need to apologize. Unless there's more than a few duplicates, it can be hard to find the original. – jscs Jun 04 '12 at 23:11

2 Answers2

3

In Objective-C you'd write something like this for instance method:

-[MyClass myMethodWithArg:andAnotherArg:]

and this for class method:

+[MyClass staticMethodWithArg:andAnotherArg:]

update to comment

I am using NSLog's __PRETTY_FUNCTION__ output format (per Zarra Studio's coding guidelines) which gives that kind of output. Apple's documentation provides following format, but it's class-context dependent:

enter image description here

Eimantas
  • 48,927
  • 17
  • 132
  • 168
  • Is it just your convention or is it based on some documentation? Could you please post a reference? – Lukáš Kubánek Jun 04 '12 at 10:06
  • Thanks for your update! The format of Apple's documentation is useless for me due to the class-context dependency. But the _pretty function_ format solves my problem. I would like to wait for another answers and if nobody offers a better solution, I will take yours. – Lukáš Kubánek Jun 04 '12 at 10:25
0

when you declare methods in .h of a class, you give a symbol in front of every method..

- negative symbol means that it is an instance method

+ positive symbol means that it is an class method

you can call a class method like this...

[ClassName yourMethod];

EDIT:

I am not exactly sure what you are asking as I have no idea about Ruby but I think this answer should help you(I guess you are looking if a class contains certain method) https://stackoverflow.com/a/1135522/919545

Community
  • 1
  • 1
Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • I know this, of course. :-) My question is how to write it out of the code. How can I express that a method belongs to a class and what type is it? – Lukáš Kubánek Jun 04 '12 at 10:01
  • Thanks for your efforts, but my question has nothing to do with coding. I want to write **in a text** that a class has a method with a name and a specific type (instance/class). – Lukáš Kubánek Jun 04 '12 at 10:15