开发者

How to use functions?

开发者 https://www.devze.com 2023-03-03 20:12 出处:网络
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 heade

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

精彩评论

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