Can I make it so I don't have to unwrap a variable everytime?

Here's the code I have:
Code Block
myGSlot.physicsBody = SKPhysicsBody(rectangleOf: size)
myGSlot.physicsBody!.affectedByGravity = true
myGSlot.physicsBody!.affectedByGravity = true
myGSlot.physicsBody!.isDynamic = true
myGSlot.physicsBody!.restitution = 0.2

Is there a way I don't have to constantly unwrap myGSlot.physicsBody?


Answered by OOPer in 635029022
How is this?
Code Block
let physicsBody = SKPhysicsBody(rectangleOf: size)
physicsBody.affectedByGravity = true
physicsBody.affectedByGravity = true //Not sure why again
physicsBody.isDynamic = true
physicsBody.restitution = 0.2
myGSlot.physicsBody = physicsBody


Accepted Answer
How is this?
Code Block
let physicsBody = SKPhysicsBody(rectangleOf: size)
physicsBody.affectedByGravity = true
physicsBody.affectedByGravity = true //Not sure why again
physicsBody.isDynamic = true
physicsBody.restitution = 0.2
myGSlot.physicsBody = physicsBody


Can I make it so I don't have to unwrap a variable everytime?
 
 
Q