开发者

objective c import once

开发者 https://www.devze.com 2022-12-22 23:45 出处:网络
I have a header file with a bunch on statics like static NSString * SOME_NAME = @开发者_StackOverflow社区\"someMeaning\";

I have a header file with a bunch on statics like

static NSString * SOME_NAME = @开发者_StackOverflow社区"someMeaning";

What is the best way to import this? Should I define them some other way?

I tried just using the #import statement but any file that imports it gives me a warning saying SOME_NAME defined but not used...


Try declaring it in the header file as

extern NSString * const SOME_NAME;

And defining it in some implementation file as

NSString * const SOME_NAME = @"SOME_NAME"

The position of the const keyword is important, because that is what makes the pointer itself a constant.


That's a warning, not an error. It's here to help you find variables you don't need anymore. But that kind of variables should be declared as extern, IMHO.

0

精彩评论

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