0

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.

3
  • That should return an (NSString *) Commented Oct 14, 2010 at 21:41
  • First off your voiding your return. Think you should start with some basic tutorials first Commented Oct 14, 2010 at 21:41
  • -(NSString*)ok { NSString* myString = @"OK!"; return myString; } Commented Oct 14, 2010 at 21:47

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.