And*_*Shi 3 cocoa-touch objective-c ios
我定义了一个像这样的新类:
@interface SomeClass : NSObject {
int wide;
}
- (id)initWithWide:(int)value;
@end
Run Code Online (Sandbox Code Playgroud)
当我实现它时,initWithWide方法如下:
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide = value;
}
@end
Run Code Online (Sandbox Code Playgroud)
Xcode向我显示错误:"Expected identifier or'('".当我将"宽"变量名改为else时,没关系.所以看起来我不能在Objective-C中使用"wide"作为变量名?
@interface SomeClass : NSObject {
int wide1;
}
- (id)initWithWide:(int)value;
@end
@implementation SomeClass
- (id)initWithWide:(int)value {
self = [super init];
wide1 = value;
}
@end
Run Code Online (Sandbox Code Playgroud)
确实'宽'是一个问题.我编辑了这个问题.我也不能相信它
宽度是OSX/iOS上的typedef(MacTypes.h行~133)
struct wide {
UInt32 lo;
SInt32 hi;
};
typedef struct wide wide;
Run Code Online (Sandbox Code Playgroud)
将变量命名为宽是没有意义的;)在这种情况下,它不应该只是一些形容词 - 将它命名为宽度!