【发布时间】:2014-08-29 03:24:58
【问题描述】:
我创建了一个 constants.h 文件来在我的 iOS 应用程序中存储一些全局变量。但是,当我尝试在我的 ViewController 中访问它并附加到它时,我得到了很多错误。
这就是我的 constant.h 文件的样子:
#import <Foundation/Foundation.h>
@interface constants
#define projectURL @"http://website.com/projects";
@end
然后在我的视图控制器中,我在顶部导入常量文件:
#include "constants.h"
但是当我尝试使用以下内容记录网址时:
NSLog(@"%@", projectURL);
我得到错误:
Expected ')'
最终,我想做的是这样的:
NSString *newProjecURLString = [projectURL stringByAppendingFormat: @"/new?auth_token=%@", auth_token];
但是为此,我得到了错误:
Extraneous ')' before ';'
【问题讨论】:
-
其他人怎么说。另外请注意,将#define 放在
@interface中是没有意义的——#define 是一个预处理器指令,并且不知道@funnyface中的@interface。
标签: ios objective-c string constants