Reputation: 124
My project had zero errors/warning from Xcode 6 Beta 1 - Xcode 6 Beta 6. When I updated to Beta 7, Xcode started telling me I have about 170 errors in my project. Mainly SpriteKit methods/objects/properties. It is still giving me the errors on the actual release of Xcode 6. I know these things shouldn't be a problem, because I have had absolutely no trouble building in the past with the exact same code. To give an example:
This kind of stuff is happening all over my project. I have uninstalled/reinstalled the Xcode Betas, as well as the release several times, but to no avail. This is my biggest project yet, and I'm incredibly upset that I can't figure this out. I would hate to have to rewrite my whole project in Objective-C. I called Apple developer support, and the only things they could recommend I had already tried and they didn't work. I also can't seem to find anyone else having similar problems online.
Thanks for any help.
Upvotes: 0
Views: 72
Reputation: 93276
It looks like the physicsBody
property of SKNode
is now an Optional. The easiest fix for this will be to create an SKPhysicsBody
instance, configure it, and then assign it to your node:
let blockSprite = SKSpriteNode(...)
blockSprite.position = ...
// etc
let physicsBody = SKPhysicsBody(rectangleOfSize: blockSprite.size)
physicsBody.categoryBitMask = ContactCategory.block
// etc
blockSprite.physicsBody = physicsBody
Upvotes: 1
Reputation: 72750
I bet it's about implicitly unwrapped optionals turned into "normal" optionals.
Try appending the implicitly unwrapped optional operator !
in each line where physicalBody
is referenced, such as:
blockSprite.physicalBody!.categoryBitMask = ...
If that actually solves the problem, then for safer code I suggest you to assign the new instance of SKPhysicalBody
to a variable, do all the initialization, then assign the variable to blockSprite.physicalBody
. That way you don't have to deal with optionals.
As a general rule, even if you are 100% sure an optional contains a non nil value, it's always better to avoid implicitly unwrapped optionals - less headaches at runtime, if it happens that an unwrapped variable is actually nil.
Upvotes: 1