Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xCode / declaring Static Methods in class

Anyone know how I can declare a static method for an xcode class and then use it in my project?

I want to create a Common.h class and then do something like this in one of .m file

Common.MyStaticMethod();

I dont want to have to instantiate and instance of Common

like image 613
Arcadian Avatar asked Dec 01 '22 04:12

Arcadian


1 Answers

You will declare a class level method in Objective-C by using "+" before the method declaration.

// in Common.h
+ (void)myStaticMethod;

// call is from anywhere
[Common myStaticMethod]

That is, a "-" before method declaration means instance methods and "+" means class level method which are not related with any particular instance of the class.

like image 103
taskinoor Avatar answered Dec 04 '22 06:12

taskinoor