Justin Justin - 1 year ago 214
Swift Question

What happened to CGRectGetMidX() and CGRectGetMidY()?

I'm following a SpriteKit tutorial video from Rob Percival, and this line of code does not compile. It seems the syntax is out of date for getting the "mid x" and "mid y" values. What are the replacements for


CGPoint(x: CGRectGetMidX(self.frame),y: CGRectGetMidY(self.frame))

Answer Source

The syntax for just about everything changed with Swift 3.

You want:

man.position = CGPoint(x: self.frame.midX, y: self.frame.midY)

See the documentation for CGRect for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download