I’m making a simple program in Objective-C. It has one class with a lot of methods. I’d just like to put the methods in another file… so I could move the following
- (void) myfunc1 {...}
- (void) myfunc2 {...}
// more functions
to another file and replace the above w/ something like
#include "myNewFile.something"
I’m fine w/ putting the #include (or whatever) statement just right in the original file.
How can I do this?
You’ll need to split your methods in to different “categories,” which each get their own h and m files. You’ll also need an h and m file for the class itself. Here’s a simple little example that I think will show you what you need to do.
TestClass.h
TestClass.m
TestClass+Category1.h
TestClass+Category1.m
TestClass+Category2.h
TestClass+Category2.m
Then in whatever file is using your class, you’ll use
Now you can create an instance of class TestClass and it will have all the methods from both category1 and category2. Simply use