I am trying to make an app in iPhone since i am new so i require a little info over this matter.
I have few classes
Class 1
Class 2
Class 3
...
Class 10
I have a new NSObject Class “Utilities”. In this class i want to define some functions like
let’s say, pass a NSMutableDictonary and calculate average
-(void) calculateAvg:(NSMutableDictonary *)myDic
-(void) calculateMile:(NSMutableDictonary *)myDic
-(void) calculateAnythingElse:(NSMutableDictonary *)myDic
Now these are the functions that will be used in entire app classes, from 1 to 10. Instead of Putting these functions in each class i have made this Utilities Function.
In java i could do this
Utilities newUtil = new Utilties();
newUtil.callFunction();
However How can I do this in my iPhone, i am a bit confused if this is the work of Singleton set? Or i should use regular method by
Utilities newUtil = [Utilties alloc] init];
Then calling functions.
Now that this class will be used again and again in entire app classes
You can go with below steps:
1) Create NSObject Class “Utilities”, which you have done.
2) Add all methods which you want it as global. But with “+” instead of “-” like below:
3) Import “Utilities.h” class first in “.pch” file.
4) That’s it. Done.
You can access all above methods throughout the app like below:
Means, no need to create object. You can access static methods by class name only.
Hope you got an idea.
Happy Coding!
Cheers!