objective-c - 在 Objective-C 中使用常量的正确方法?

标签 objective-c ios

我正在为我的应用外部化一些常量,并决定使用外部文件 Constants.h。

这是正确的做法吗?我在程序错误中收到“意外的‘@’。应该将#defines 放在这个头文件中的什么位置?

//
//  Constants.h


@interface Constants : NSObject {   

}

#define height 227
#define width 40


@end

最佳答案

在您的 Constant.h 文件中,仅像这样定义 Constant:

#define height 227
#define width 40

并将这个 Constant 文件导入到您的 Prefix.pch 文件中

#ifdef __OBJC__

       #import "Constant.h"

#endif

关于objective-c - 在 Objective-C 中使用常量的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9749988/

相关文章:

ios - 使用 NSURLSession 等待 HTTP 请求的响应 - Objective C

ios - 如何用其他方法识别通过蓝牙扫描的设备

iOS |呈现新 ViewController 对象的方法与使用 Segue 的区别

iphone - 点击 uipickerview 时键盘不退出

Objective-c - iOS - 隐藏/取消隐藏标签、文本字段等

iPhone 使工具栏在 UITableView 中可见

ios - 使用 Safariservices swift 如何围绕小黑框进行编码

ios - UITableViewCell 不会在 swift 中保持突出显示

objective-c - 完成时调用主队列的单元测试异步队列模式

ios - 如何解决 iOS 中的 EAGLContext 崩溃?