错误:无法在@interface或@protocol中声明变量

时间:2012-06-13 21:53:53

标签: objective-c xcode macos xcode4 xcode4.2

我点击了Modernize Project然后我遇到了一些编译错误。 (我拍了快照)

错误是:无法在@interface或@protocol

中声明变量

以下是复制和粘贴格式的代码。

#import <Cocoa/Cocoa.h>
#import "AJHBezierUtils.h"

@interface NSBezierPath (WBBezierPath) 

NSBezierPath        *flattenPath;

NSPointArray        points;

int                 numPoints;


+(NSBezierPath*)roundedPath:(NSRect)aRect radius2:(int)rad2;


-(NSPoint ) getLinePoints:(NSPoint )p1 p2:(NSPoint)p2  withDistance:(int )pointDistance;

- (NSPoint *)pointsFromPathWithDistance:(int)distance numberOfPoints:(int *)numberOfPoints;


- (float)distanceBetweenPoint:(NSPoint)a andPoint:(NSPoint)b;

- (int)numberOfPoints;

Here is the error in XCode

1 个答案:

答案 0 :(得分:11)

你需要接口ivars的大括号:

@interface NSBezierPath (WBBezierPath)
{
  NSBezierPath        *flattenPath;
  NSPointArray        points;
  int                 numPoints;
}

但是,因为您要定义类别,所以不允许使用ivars。您需要使用属性:

@interface NSBezierPath (WBBezierPath)

@property (nonatomic, strong) NSBezierPath *flattenPath;

/* Methods */

@end