Reputation: 900
I declare an interface with some functions and some methods. Instead of declaring:
-(void)foo;
+(void)bar;
I declare:
-(void)foo;
void bar();
I think it's fine. The compiler thinks it's fine. Do other programmers also think it's fine?
Upvotes: 0
Views: 116
Reputation: 63697
Concerns when choosing a C function or a static method: (from the top of my head)
xxxUtils
classes). Otherwise use a C function. __attribute__((overloadable))
.Upvotes: 2
Reputation: 31745
I don't quite understand the point of the question. You can similarly declare them all together:
-(void)foo;
+(void) bar;
void bar();
All are legal in objective C and can co-exist with the same name as they are different entities (instance method, class method, C function). You can call void bar()
from either of the former without issue, but not v/v as void bar() doesn't get passed a reference to self
.
If the question is rather an issue of style, I would declare C functions separately from the @interface as they are not Objective-C.
With recent versions of Clang there is no need to declare these at all if they are not for public use...
update
Having read @Jano's answer, I now understand the point of the question a little more: why choose a class method over a function where either can achieve the same result (neither have access to self
). These days I tend to always use the class method, it just seems to make sense in an obj-C context. Jano's answer seems pretty exhaustive as to why.
Upvotes: 1
Reputation: 46563
Its just a matter of USED-TO.
I would go for Objective-C style of methods unless I need some functions that are only available in C like pow().
Even if you want to add a C method, I feel it should be in a separate file, as AllCMethods.c
It will be easier to recall, remember, use all obj-c methods and C-methods.
Upvotes: 0