iOS:错误与#34; Constants.h"

时间:2013-04-11 11:23:25

标签: ios xcode uiviewcontroller

我已经声明了一个常量头文件:" Constants.h"。它包含以下声明:

extern const NSString   *Const_alertPayantMessage = @"test";
extern const NSString   *Const_alertPayantTitle   = @"Wooooops!!!";
extern const int        *Const_statutPayant       = 1;

我用这种方式使用了这个常量:

int x = 1;

    if (x == Const_statutPayant) {
        UIAlertView* mes=[[UIAlertView alloc] initWithTitle:Const_alertPayantTitle
                                                    message:Const_alertPayantMessage delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];

        [mes show];
        [avPlayerError play];
    }else{
        [avPlayer play];

不幸的是,我无法运行我的应用程序,因为我有这样的错误消息:

clang: error: linker command failed with exit code 1 (use -v to see invocation)

你有什么想法吗?

2 个答案:

答案 0 :(得分:3)

“Constants.h”应包含:

extern const NSString   *Const_alertPayantMessage;
extern const NSString   *Const_alertPayantTitle;
extern const int        Const_statutPayant;

“Constants.m”应包含:

const NSString   *Const_alertPayantMessage = @"test";
const NSString   *Const_alertPayantTitle   = @"Wooooops!!!";
const int        Const_statutPayant       = 1;

答案 1 :(得分:0)

Constant.h 应该像

NSString   *  const kAlertPayantMessage;
NSString   *  const kAlertPayantTitle;

你的 Constant.m 应该像

NSString   *  const kAlertPayantMessage = @"test";
NSString   *  const kAlertPayantTitle   = @"Wooooops!!!";  

Why you have to use NSString* const instead of const NSString * ?