声明的extern的NSString导致链接错误 [英] Declaring extern NSString causes linker error

查看:703
本文介绍了声明的extern的NSString导致链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是荒谬的,即时通讯试图建立一个完善的布尔在app声音转的。我不断收到

This is ridiculous, im trying to create a sound bool to turn of in app sounds. I keep getting

Undefined symbols for architecture i386:
"_kPlaySoundPrefsKey", referenced from:
  -[AppDelegate application:didFinishLaunchingWithOptions:] 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)

我已经检查了我的所有文件都在构建阶段联系在一起,我删除了的appdelegate .M那里即时得到错误之前我甚至去调用我的任何视图控制器的布尔,并重新导入它在构建阶段。经过我已经制定相关framweworks。我甚至已经查了previous应用程序,我用同样的code和code这似乎是没有错误完全一样(以x $ C $的C previous版本内置)制成。服用右后卫基本原则我,只要我加入以下code到我的应用程序委托,

I have checked that all my files are linked in build phases, I have deleted the appdelegate .m where im getting the error before I even get to call the bool in any of my view controllers, and re imported it in build phases. Checked I have relevant framweworks in place. I have even checked a previous app I made with same code and the code it appears to be exactly the same with no error (built with previous version of xcode). Taking it right back to basics I get the error as soon as I add the following code to my App Delegate,

.H

#import <UIKit/UIKit.h>
extern NSString *kPlaySoundPrefsKey;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

.M

#import "AppDelegate.h"
#import <AudioToolbox/AudioToolbox.h> 

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
 {

NSDictionary *defaultDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
 forKey:kPlaySoundPrefsKey];

return YES;
}

如果我更改的extern的NSString * kPlaySound prefsKey; 的NSString * kPlaySound prefsKey; 然后它建立崩溃...林的想法,现在

If I change extern NSString *kPlaySoundPrefsKey; to NSString *kPlaySoundPrefsKey; it builds then crashes...Im out of ideas now

推荐答案

感谢您的帮助球员

我添加

的NSString * kPlaySound prefsKey = @playSoundKey;

[NSUserDefaults的standardUserDefaults] registerDefaults:defaultDict];

到应用程序委托。这固定它

to app delegate. That fixed it

这篇关于声明的extern的NSString导致链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆