-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.

Beny
  • 890
  • 2
  • 15
  • 26

1 Answers1

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.

yan.kun
  • 6,820
  • 2
  • 29
  • 38
  • 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`. – Beny Jan 05 '13 at 17:13
  • It seems that my question correspond to this one in reality : http://stackoverflow.com/questions/3572448/objective-c-call-function-on-another-class I'm trying to make some tests and come back then. – Beny Jan 05 '13 at 17:22
  • 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. – Beny Jan 05 '13 at 17:51