我在Xcode中开始了一个新的iOS项目。添加了两个文件:“constants.h”和“constants.m”,其中包含我在其他文章中看到的内容:
Constants.h
#import <Foundation/Foundation.h>
/// Holds the username for connection to the API
extern NSString * const PSUsername_preferences;
/// Holds the password for connection to the API
extern NSString *const PSPassword_preferences;
///Holds the (hopefully) secure server URL. (Defaults to https://API.SomewhatURL.de)
extern NSString *const PSServername_preferences;
和constants.m:
#import "Constants.h"
NSString *const PSUsername_preference = @"username_preferences";
NSString *const PSPassword_preference = @"password_preferences";
NSString *const PSServer_preference = @"servername_preferences";
我确信,.m文件已分配给我的ios-target构建。 我也很确定,该文件是在Build Configurations-Compile Sources下添加的。
接下来,我将“Constats.h”添加到我的pch文件中:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#endif
我可以在AddDelegate
中指定其中一个:
NSString * value = PSUsername_preferences;
尼斯。 但是:如果我尝试构建它,我会得到一个奇怪的链接器错误:
架构i386的未定义符号: “_PSUsername_preferences”,引自: - AppDelegate.o中的[AppDelegate applicationWillResignActive:] ld:找不到架构i386的符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
这种情况发生在一个新创建的项目中。我的构建设置似乎没问题,我已经在Build-Settings下检查了'Architectures'路径。所有这些都显示'ArmV7'而不是i386,所以最新情况如何?
我在Xcode 4.6.3
以及Xcode 5
下进行了测试。
答案 0 :(得分:3)
逐字阅读你的常名。或者添加一些空格以便于阅读。
extern NSString * const PSUsername_preferences;
NSString * const PSUsername_preference
你看到了区别吗?在定义的末尾添加字母s
。