我想最初将一个CGPoint属性设置为特定的点(屏幕中央)。其他方法可能随后希望更改此属性。我的想法是在getter中初始化它,如果为空,则无效参数类型“struct CGPoint”到单元表达式。我还尝试使用if属性==nil或0,但没有成功。
有什么想法吗?
-(CGPoint)graphOrigin
{
// initialise to centre of screen if has not been set
if(!_graphOrigin) // this expression is causing the problem
{
CGPoint origin = CGPointMake(self.bounds.origin.x + self.bounds.size.width / 2, self.bounds.origin.y + self.bounds.size.height / 2);
_graphOrigin = origin;
}
return _graphOrigin;
< p > } < /p >