objective-c - 在 Cocoa-Touch 的 header 中放置 "const double NA = 1e-300"错误,但在 Cocoa 中则不然?

标签 objective-c xcode cocoa-touch cocoa

我尝试将 const double NA = 1e-300; 放入 Cocoa-Touch 的头文件中,但 Xcode 不喜欢它。然而,当我在 Cocoa(64 位 MAC)中执行此操作时,它工作得很好。

??????

错误:

<小时/>

Duplicate symbol _NA in /Users/jdl/Library/Developer/Xcode/DerivedData/iExperiment-chcmotcyeolxeacnidtlgofkcihz/Build/Intermediates/iExperiment.build/Debug-iphonesimulator/iExperiment.build/Objects-normal/i386/ViewController.o and /Users/jdl/Library/Developer/Xcode/DerivedData/iExperiment-chcmotcyeolxeacnidtlgofkcihz/Build/Intermediates/iExperiment.build/Debug-iphonesimulator/iExperiment.build/Objects-normal/i386/AppDelegate.o for architecture i386

<小时/>

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1

<小时/>
#import <UIKit/UIKit.h>

const double NA = 1e-300; // <------------- Error in Cocoa-Touch but not Cocoa ??  
// So where do I put this so it doesn't error out in Cocoa-Touch?? 

@interface ViewController : UIViewController
{
    UITextView *tvText;
}
@end

最佳答案

头文件中定义的常量应如下所示:

__unused static const double NA = 1e-300; 

__unused 是为了抑制未使用变量的编译器警告,static 可以防止常量暴露给链接器,这将解决您的问题。

关于objective-c - 在 Cocoa-Touch 的 header 中放置 "const double NA = 1e-300"错误,但在 Cocoa 中则不然?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10438648/

相关文章:

objective-c - Leaks 在 iPad 上使用 CoreData 报告的真正奇怪的数据

iphone - 我的类应该转换为核心数据管理对象,还是核心数据管理对象

objective-c - 制作 Objective-C 类的不可变和可变版本的最有效方法是什么?

iphone - loadView的正确实现方式?

iphone - 创建一个 UIWebView 并以编程方式加载网站

ios - UIScrollView contentOffset 在推送另一个 View 后发生变化

iphone - 如何更改 UILabel 的大小

ios - 共享扩展不上传全尺寸图像

c++ - Xcode 中的 CppUnit(或一般的 C++ 单元测试)

ios - AFNetworking 2.0//如何读取响应头