MrDatabase
MrDatabase

Reputation: 44505

Organizing code in Objective-C and XCode

I have some Objective-C code that looks like this:

#define myVar 10
float f = 10.0;
- (void) myFunc{ ... }

#define anotherVar 20
float z = 30.0;
- (void) myFunc2{ ... }

// and so on

It's all in one class. I'd like to put the first block of code into another file and just reference it somehow. So the above code would end up looking something like this:

// some reference to the code... #import?  #include?  I don't know...

#define anotherVar 20
float z = 30.0;
- (void) myFunc2{ ... }

How can I do this? I just want the most basic, simple, and crude solution. Cheers!

Upvotes: 0

Views: 718

Answers (1)

Tom Dalling
Tom Dalling

Reputation: 24145

You can do it with an include. For example:

File1.m

#define myVar 10
float f = 10.0;
- (void) myFunc{ ... }

File2.m

#include "File1.m"

#define anotherVar 20
float z = 30.0;
- (void) myFunc2{ ... }

Just make sure you remove File1.m from the build because it won't compile by itself.

Upvotes: 2

Related Questions