Skullhouseapps
Skullhouseapps

Reputation: 496

How to use functions?

I define a function in a separate .m file and then when I want to use it (in other implementation files), I just don't know what to import, to actually see it.

Upvotes: 1

Views: 68

Answers (2)

MusiGenesis
MusiGenesis

Reputation: 75296

Assuming that you already have a matching .h file for your .m file, you just need to add #import "MyUtilityClass.h" to the header file of whatever other class you want to use your class from.

Upvotes: 1

Chuck
Chuck

Reputation: 237020

You need to create a header that declares the function and import that. So if you have the following file:

MyFavoriteTransformer.m

NSString *MyFavoriteTransformer() {
    return @"Hot Rod"; // Come on -- he's awesome!!!!
}

You'll want to have a corresponding file like this:

MyFavoriteTransformer.h

NSString *MyFavoriteTransformer();

Upvotes: 2

Related Questions