IOS Weird编译器错误:“;之前为']';'在单例中对NSString常量使用set-ter [英] IOS Weird compiler error: "expected ']' before ;' using set-ter for NSString constant in singleton
问题描述
我有最奇怪的错误!在Xcode中,我有一个具有以下定义的单例(文件为: MyGizmoClass.h
):
I have the weirdest error! In Xcode I have a singleton with the following defined (file is: MyGizmoClass.h
):
NSString *plistPath;
NSString *dataDomain;
NSString *pathToChatScript;
NSString *pathToUpdates;
和
@property (nonatomic,retain) NSString *plistPath;
@property (nonatomic,retain) NSString *dataDomain;
@property (nonatomic,retain) NSString *pathToChatScript;
@property (nonatomic,retain) NSString *pathToUpdates;
我有一个 Constants.h
文件(我在.pch文件的开头是 #import
),其中包含:
I have a Constants.h
file (which I #import
early in my .pch file) that contains:
#define kUserPlistName @"userPlist.plist"
#define kDataDomain @"http://www.jann.com/";
#define kPathToChatScript @"path/top/chatscript.cgi";
#define kPathToupdates @"pathtoupdates/";
好的,到目前为止,很好。
Okay, so far, so good.
我的.pch文件中的顺序是这样的:
The order, in my .pch file is as such:
#import "Constants.h"
#import "MyGizmoClass.h"
,然后在 Constants.h
文件,我这样做:
and then later in the Constants.h
file I do this:
#import "FileFunctions.h"
好的,好的设置。这应该可以正常工作,一个带有3个NSString的单例。但是当我尝试在 FileFunctions.h
中执行此操作时,在编译器中出现一个奇怪的错误:
Okay, fine setup. This should work, a singleton with 3 NSStrings. But when I try to do this in FileFunctions.h
I get a weird error in the compiler:
FileFunctions.h
[myGizmoClass setDataDomain: kDataDomain];
[myGizmoClass setPathToChatScript: kPathToChatScript];
[myGizmoClass setPathToUpdates: kPathToupdates];
[myGizmoClass setPlistPath:[[myGizmoClass libraryDir] stringByAppendingPathComponent:kUserPlistName]];
编译器结果
在;之前的']'
这是怎么回事?我得到了3次...一次用于setDataDomain,一次用于setPathToChatScript,一次用于setPathToUpdates。但是 kUserPlistName
没有错误。当我在 FileFunctions.h
中执行此操作时,一切都很好:
What is going on? I get this 3 times ... one for setDataDomain, one for setPathToChatScript and one for setPathToUpdates. But no error on kUserPlistName
. When I do this in FileFunctions.h
then all is well:
[myGizmoClass setDataDomain: @"http://www.jann.com/"];
[myGizmoClass setPathToChatScript: @"path/top/chatscript.cgi"];
[myGizmoClass setPathToUpdates: @"pathtoupdates/"];
编译器结果
一切都很好。
我不知道这一点。稍后(下面的4行),我将执行以下操作:
I cannot figure this out. Later (4 lines below this) I do the following:
[myGizmoClass setPlistPath:[[myGizmoClass libraryDir] stringByAppendingPathComponent:kUserPlistName]];
那样有效!为什么使 kUserPlistName
无效,而 kDataDomain
无效?这可能是如此简单...但是我不能为我的一生而看到它!
And THAT works! Why would subbing kUserPlistName
work, yet kDataDomain
wouldn't? This is probably SO easy...but I cannot, for the life of me, see it!
附录
我发现在任何地方我都使用 kDataDomain
, setPathToChatScript
或<$ c $我在代码中使用c> setPathToUpdates
I have found that EVERYWHERE I use kDataDomain
, setPathToChatScript
or setPathToUpdates
in the code I get the same
编译器结果
期望在']'之前;
错误! :(
谢谢!
推荐答案
不包括分号在您的 #define
s中。
Don't include the semicolon in your #define
s.
编译器将完全替换您所拥有的内容,因此它们等效:
The compiler substitutes in exactly what you have there, so these would be equivalent:
[myGizmoClass setPathToUpdates: kPathToupdates];
[myGizmoClass setPathToUpdates: @"pathtoupdates/";]; // obvious syntax error
这篇关于IOS Weird编译器错误:“;之前为']';'在单例中对NSString常量使用set-ter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!