开发者

How to use functions?

I开发者_如何学C 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.


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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜