我想问一下有什么用背后的原因FOUNDATION_EXPORT,而不是extern在目标C项目.
我已经检查了这个问题,使用FOUNDATION_EXPORT得到了高达340分(第一名),而extern只使用了74分(第二名).
谁有人解释原因?是否有任何实际的理由FOUNDATION_EXPORT代替使用extern?
谢谢!
在Objective C中使用extern有多好?它确实使某些部分的编码变得容易..但它不会破坏对象的方向吗?
这是荒谬的,我试图创建一个声音bool来转换应用程序的声音.我一直在
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)
Run Code Online (Sandbox Code Playgroud)
我已经检查过我的所有文件都是在构建阶段链接的,我已经删除了appdelegate .m,在我得到错误之前,我甚至可以在任何视图控制器中调用bool,并在构建阶段重新导入它.检查我有相关的framweworks到位.我甚至检查了我使用相同代码制作的以前的应用程序,它看起来完全相同,没有错误(使用以前版本的xcode构建).回到基础,我将以下代码添加到App Delegate后立即收到错误,
.H
#import <UIKit/UIKit.h>
extern NSString *kPlaySoundPrefsKey;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
Run Code Online (Sandbox Code Playgroud)
.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;
}
Run Code Online (Sandbox Code Playgroud)
如果我改变extern …
我猜我只会使用UIKIT_EXTERN,如果我的项目中有可能使用该变量的C++代码.
如果是这种情况,用UIKIT_EXTERN声明所有外部可用的常量是否安全?
为什么我不再看到这个?