mrueg
mrueg

Reputation: 8225

"Official" syntax for referring to method of a class in Objective-C?

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?

Upvotes: 3

Views: 304

Answers (3)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

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

Upvotes: 5

Barry Wark
Barry Wark

Reputation: 107754

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.

Upvotes: 12

Marcus S. Zarra
Marcus S. Zarra

Reputation: 46718

If you are referring to a method like:

+ (void)someClassMethod;

on class MyObject then you would call it like this:

[MyObject someClassMethod];

Upvotes: -1

Related Questions