-2

I'm looking for a (certainly basic) thing to do in Objective-C/Cocoa : I would like to split my code into multiple files (one for functions, one for tab view N°1 methods, one for tab view N°2 methods, etc) to make my projects well organized.

I would like to be able to call functions and/or methods from my "AppDelegate.m".

But I don't know how to formulate this question correctly to find help around the web. I come from Delphi, and in Delphi you have just to create a new .PAS file and declare it in USES section.

We are in 2013, so it's certainly an ultra-basic way to code properly via XCode :)

Thanks in advance for any help.

3
  • Can you be more specific? Commented Jan 5, 2013 at 17:01
  • Ah ! So, I would to put all my functions (for string manipulations for example) in another file. Then, from my main "AppDelegate.m" I'll call these functions. Commented Jan 5, 2013 at 17:06
  • Now that it seems easy, I'm sure I'll get some downvotes... :D Commented Jan 5, 2013 at 17:53

1 Answer 1

4

Basically, it's the same - except with the C background of Objective-C you will have to create 4 files. Two header files (.h) and two implementations (.m).

Instead of the uses section you will use the #import statement at top of the .m files.

#import "myClassHeader.h"

As this belongs to the more basic tasks in Objective-C or any C-based language, you should start with reading some beginners tutorial, how to define classes and methods.

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

3 Comments

Thanks for your reply ! Ah ok, so I just tried that. I created a new class MyFunctionName(.h and .m). In AppDelegate.m I called #import "MyFunctionName.h". In MyFunctionName.m I created a basic function - (void)myExample:(NSString *)Value { NSLog(Value); }. Now, I would to be able to call it from AppDelegate.m.
It seems that my question correspond to this one in reality : stackoverflow.com/questions/3572448/… I'm trying to make some tests and come back then.
Ok cool. It was that ! I didn't find anything about MyFunctionName *myScript = [[MyFunctionName alloc] init]; before, so I didn't know how to call the function or method from 2nd class. But creating a new class was well the solution to separate my long code into small differents classes, well organized.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.