Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 为什么只能在头文件中定义NSString常量?_Objective C_C_Xcode - Fatal编程技术网

Objective c 为什么只能在头文件中定义NSString常量?

Objective c 为什么只能在头文件中定义NSString常量?,objective-c,c,xcode,Objective C,C,Xcode,一个奇怪的objective-c新手问题。我注意到我可以在.h文件中定义NSString,但不能在.m文件中定义。。。为什么? 有关的声明是: #define kSomeString @"This is a string" 如果该声明在.m文件中出现,则该声明将失败并出错。您也可以在实现文件中定义它们 #import "SAiPadHomeViewController.h" #define hugo @"Test" @interface SAiPadHomeViewController (

一个奇怪的objective-c新手问题。我注意到我可以在.h文件中定义NSString,但不能在.m文件中定义。。。为什么?

有关的声明是:

#define kSomeString @"This is a string"

如果该声明在.m文件中出现,则该声明将失败并出错。

您也可以在实现文件中定义它们

#import "SAiPadHomeViewController.h"

#define hugo @"Test"

@interface SAiPadHomeViewController ()
@end

@implementation SAiPadHomeViewController
@end
这个例子很有效——试试看


格里茨

您也可以在实现文件中定义它们

#import "SAiPadHomeViewController.h"

#define hugo @"Test"

@interface SAiPadHomeViewController ()
@end

@implementation SAiPadHomeViewController
@end
这个例子很有效——试试看


格里茨

怎么了?+1@JamesMcLaughlin。无论是在头文件还是在实现文件中,它的工作原理都应该完全相同。编译器当然不在乎。@CarlNorum我可以确认你的结果,没有错误。Matthew Carriere,你的代码一定有问题。有什么错误?+1@JamesMcLaughlin。无论是在头文件还是在实现文件中,它的工作原理都应该完全相同。编译器当然不在乎。@CarlNorum我可以确认你的结果,没有错误。Matthew Carriere,你的代码一定有问题。