可能重复:
在iOS应用程序中存储全局常量的位置?
我想将配置变量存储在一个中心位置.变量在运行时不会更改.它们应该可以从项目中的任何类访问.
我目前的方法是使用一个GlobalSettings.h文件,其配置变量定义如下
#define kCacheAge 10.0 //Max. Cache Age in Seconds
#define kNavigationTitleTint colorWithRed:0.443 green:0.471 blue:0.502 alpha:1.0
#define kNavigationTitleFont boldSystemFontOfSize:20.0
Run Code Online (Sandbox Code Playgroud)
......并在我需要的地方加入他们的名字.
缺点:
有没有更好的方法来做到这一点,也许避免上述缺点?存储配置变量的最佳实践?
如果GlobalSetting.h在项目前缀标题中包含标题,它将自动包含在项目的每个文件中.在项目中查找名为的文件<YourProjectName>-Prefix.pch.iOS项目的标准版本如下所示:
//
// Prefix header for all source files of the 'IOSTest' target in the 'IOSTest' project
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Run Code Online (Sandbox Code Playgroud)
#import "GlobalSettings.h"在这种情况下,您将在Foundation导入下面添加.
| 归档时间: |
|
| 查看次数: |
397 次 |
| 最近记录: |