[英]In Xcode and IOS projects I can't use constants. Got linker build errors
I started a new iOS project in Xcode. 我在Xcode中开始了一个新的iOS项目。 Added two files: "constants.h" and "constants.m" with this content I saw here in other articles:
添加了两个文件:“constants.h”和“constants.m”,其中包含我在其他文章中看到的内容:
Constants.h 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;
And the constants.m: 而constants.m:
#import "Constants.h"
NSString *const PSUsername_preference = @"username_preferences";
NSString *const PSPassword_preference = @"password_preferences";
NSString *const PSServer_preference = @"servername_preferences";
I am sure, the .m file is assigned to build for my ios-target. 我确信,.m文件被指定为我的ios-target构建。 I am also sure, the file is added under Build Configurations- Compile Sources.
我也很确定,该文件是在Build Configurations-Compile Sources下添加的。
Next I added the "Constats.h" to my pch - file: 接下来,我将“Constats.h”添加到我的pch文件中:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#endif
and I can assign one of these in let say AddDelegate
: 我可以在
AddDelegate
指定其中一个:
NSString * value = PSUsername_preferences;
Nice. 尼斯。 But: If I try to build this, I get a strange linker error:
但是:如果我尝试构建它,我会得到一个奇怪的链接器错误:
Undefined symbols for architecture i386: "_PSUsername_preferences", referenced from: -[AppDelegate applicationWillResignActive:] in AppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)
架构i386的未定义符号:“_ PSUsername_preferences”,引用自: - AppDelegate.o中的[AppDelegate applicationWillResignActive:] ld:未找到架构i386的符号clang:错误:链接器命令失败,退出代码为1(使用-v为看调用)
This happens with a new created project just for this case. 这种情况发生在一个新创建的项目中。 My build settings seem OK and I already checked 'Architectures' path under Build-Settings.
我的构建设置似乎没问题,我已经在Build-Settings下检查了'Architectures'路径。 All of they show 'ArmV7' but not i386, so whats going on?
所有这些都显示'ArmV7'而不是i386,所以最新情况如何?
I tested it on Xcode 4.6.3
as well as under Xcode 5
. 我在
Xcode 4.6.3
以及Xcode 5
下进行了测试。
Read your constant names letter by letter. 逐字阅读你的常名。 Or add some whitespace for easier readability.
或者添加一些空格以便于阅读。
extern NSString * const PSUsername_preferences;
NSString * const PSUsername_preference
You see the difference? 你看到了区别? Add the letter
s
at the end of your definitions. 在定义的末尾添加字母
s
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.