Ted Philip Lat - 1 month ago 11x
Objective-C Question

# Swift - How to change value of get-only property

Hi I'm new to swift and OpenGL. I'm following a tutorial in written in objective C and I'm converting it to Swift 2.0

Here is the code

``````float radius = self.view.bounds.size.width/3;
GLKVector3 center = GLKVector3Make(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 0);
GLKVector3 P = GLKVector3Subtract(touchPoint, center);

P = GLKVector3Make(P.x, P.y * -1, P.z);

float length2 = P.x*P.x + P.y*P.y;

else
{
P.z = radius2 / (2.0 * sqrt(length2));
float length = sqrt(length2 + P.z * P.z);
P = GLKVector3DivideScalar(P, length);
}
``````

Here is my Swift Code

``````    let radius: CGFloat = self.view.bounds.size.width/3
let center: GLKVector3 = GLKVector3Make(Float(self.view.bounds.size.width / 2), Float(self.view.bounds.size.height/2), 0.0)
var P: GLKVector3 = GLKVector3Subtract(touchPoint, center)

P = GLKVector3Make(P.x, P.y * -1, P.z)

let length = P.x * P.x + P.y * P.y

P.z = sqrt(Float(radius2) - Float(length)) //the error is here
} else {
//other code
}
``````

I cant change the value of P.z, it says

"Cannot assign property: 'z' is a get-only property"

`````` if(Float(length) <= Float(radius2)){