views:

133

answers:

3

In Ruby, when referring to the "downcase" method of the class "String", I write String#downcase. When talking about the "new" class method, I write String.new.

Is there something similar for Objective-C?

A: 

If you are referring to a method like:

+ (void)someClassMethod;

on class MyObject then you would call it like this:

[MyObject someClassMethod];
Marcus S. Zarra
Yes, I know how to call a method in Obj-C. What I mean is: how would you refer to a method in, say, documentation or comments, in a less verbose way than "the method someMethod of [the class] SomeClass".
mrueg
+5  A: 

gdb uses +[MyClass foo] and -[MyClass bar];

Nikolai Ruhe
+12  A: 

Given a class declaration like this

@interface MyClass (NSObject)
{}

+ (id)classMethod;
- (id)instanceMethod;
@end

it is common practice to refer to classMethod as +[MyClass classMethod] or more compactly +classMethod if the class is clear. Similarly, I would refer to instanceMethod as -[MyClass instanceMethod] or -instanceMethod.

Barry Wark
Great answer, I always use the class name (the **+** or **-** disambiguates class and instance methods) and the shorthand form you mention (for methods in the same class, or when the class is clear) is quite useful. In addition, remember that for methods which accept one or more parameters, use the full selector name, including colons. For example, `+[NSString stringWithFormat:]`, `-[NSString initWithFormat:arguments:]`, etc.
Quinn Taylor
Good answer. When referring to a method in prose, I've always used the `(+|-)methodWithArgs:moreArgs:` way to make it clear which was intended.
johne