Reputation: 1453
I have class1.m . I declared a method and written in it. Now i need to call it into another class. How can I make it? Can we use extern for it like we use for variables. Thank you.
Upvotes: 0
Views: 111
Reputation:
I highly recommend reading Apple's Objective-C Programming Guide which will cover the fundamentals you need to know.
Upvotes: 1
Reputation: 95599
You should separate your declaration and definition, and place the declaration for class1 in class1.h. Then, you should include class1.h using #import "class1.h"
in your source file for class2. Within class2, you can instantiate and use class1 as follows:
class1* instance_of_class1 = [[class1 alloc] init]; [class1 invokeMyMethod];
When you are done using your instance, be sure to decrement the reference count via release as in:
[instance_of_class1 release]; instance_of_class1 = nil;
Upvotes: 3