Objective c 分配包含CGPoint的类并对其进行初始化时,访问代码错误
我一直在试图找出我写的代码有什么问题,但我一点也不知道为什么它错了。我注意到的另一件事是Xcode将我的CGPoint视为指针,阻止我使用箭头符号。为了我的计划,我需要它成为一个财产 在.h文件中Objective c 分配包含CGPoint的类并对其进行初始化时,访问代码错误,objective-c,cgpoint,Objective C,Cgpoint,我一直在试图找出我写的代码有什么问题,但我一点也不知道为什么它错了。我注意到的另一件事是Xcode将我的CGPoint视为指针,阻止我使用箭头符号。为了我的计划,我需要它成为一个财产 在.h文件中 @property (nonatomic) CGPoint* directionUsed; 在控制器文件中 // up is just an instance of the class direction. // Direction is a class that returns itself s
@property (nonatomic) CGPoint* directionUsed;
在控制器文件中
// up is just an instance of the class direction.
// Direction is a class that returns itself
self.up = [[Direction alloc]initWithX:0 y: -1];
.m文件中指定的初始值设定项:
-(id)initWithX:(int)x y:(int)y{
self = [super init];
if(self){
self.directionUsed->x = x; //not letting me use dot notation
self.directionUsed->y = y;
}
return self;
}
谢谢你的帮助 问题是您将CGPoint定义为指针 只需更改代码 从 到 编辑 要将值分配给
directionUsed
,需要首先分配结构
您需要更改代码
从
到
这解决了我的大部分问题,但是现在我无法将初始值设定项的值分配给CGPoint。当我在初始化器方法上执行“self.directionUsed.x=x”时,它会给我一个错误,表示表达式不可赋值。我已经更新了我的replay。。。在不创建结构本身的情况下,无法更改结构内部的值
@property (nonatomic) CGPoint* directionUsed;
@property (nonatomic) CGPoint directionUsed;
self.directionUsed->x = x;
self.directionUsed->y = y;
CGPoint point;
point.x = x;
point.y = y;
self.directionUsed = point;