views:

72

answers:

2

Hi, i have 2 class: main.m second.m.

If i have in main.m

- (void)ok
{    
NSString *myString = @"OK!";
return myString;
}

How to call myString or "-(void) ok" function from second.m? Thanks.

+7  A: 

somewhere in second.m and assuming main.h/m defines a "Main" class

Main *m = [[Main alloc] init];
NSString *mString = [m ok];
//Do Stuff
[m release];

However, based on the fact that your example returns void and not NSString, I think you have some basic knowledge to gain first. I'm guessing you don't understand Interfaces and Implementations yet, etc.

I would suggest starting with a good basic tutorial.

MarkPowell
seconded.......
Siddharth Iyer
A: 

create an instance of main.m in second.m, then then using the created instance you can easily access its own variable. i support MaskPowell's answer.

suse
Thankk to all!!
pakizip