The "official" syntax for invoking a class method in Objective-C?

In Ruby, referring to the "downcase" method of the "String" class, I write the string String #. When it comes to the method of the β€œnew” class, I write String.new.

Is there something similar for Objective-C?

+3
source share
3 answers

Given a class declaration like this

@interface MyClass (NSObject)
{}

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

Common practice is classMethodas +[MyClass classMethod]or more compact +classMethodif the class is clear. Similarly, I would call instanceMethodas -[MyClass instanceMethod]or -instanceMethod.

+12
source

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

+5
source

, :

+ (void)someClassMethod;

MyObject, :

[MyObject someClassMethod];
-1

Source: https://habr.com/ru/post/1716515/


All Articles