So This Drove Me Bonkers…

So I recently updated Xcode 8 beta 6, up from an earlier beta (3 or 4 not sure). After downloading and installing the application, I opened my ongoing Swift project and began to work. I added two new methods to my App Controller class, but each one had no real guts, they were essentially empty shells. I cleaned the project ([Shift]+[Cmd]+[K]) then rebuilt the project ([Cmd]+[B]). The following error from the linker greeted me:

Screen Shot 2016-08-26 at 1.01.16 AM

The linker is essentially complaining that it does not recognized the method signature used with the SCNPhysicsShape class. The responsible piece of code was found here:

private func setupPlane() {

    // create plane geometry with size and material properties
    let myPlane = SCNPlane(width: 10000.0, height: 10000.0)
    myPlane.firstMaterial!.diffuse.contents = NSColor.orange.cgColor
    myPlane.firstMaterial!.specular.contents = NSColor.white.cgColor

    // intialize noe
    let planeNode = SCNNode()
    // assign plane geometry to the node
    planeNode.geometry = myPlane

    // rotate -90.0 about the x-axis
    let rotMat = SCNMatrix4MakeRotation(-CGFloat(M_PI/3.0), 1.0, 0.0, 0.0)
    planeNode.transform = rotMat
    planeNode.position = SCNVector3Make(0.0, 0.0, 0.0)

    // setup the node's physics body property
    planeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: myPlane, options: nil))
    planeNode.physicsBody!.categoryBitMask = PhysicsMask3DOF.plane.rawValue

    // add to scene
    sceneView.scene!.rootNode.addChildNode(planeNode)
}

At line 19, a physics body object is assigned to the physics body property of a scene node object. Inside the physics body initialization method, a physics shape object is created using an initialization method from the SCNPhysicsShape class.

This drove me up a wall and kept me up for many hours. I was stuck as many queries online in which the Xcode spit out similar or the same messages had many different solutions that did not work for me. I literally posted the a question on StackOverflow as a last ditch effort. I did not expect that my question would be read let alone answered and so quickly! Around 7:30am in the morning, I checked StackOverflow and there was exactly one response, the one I needed. Turns out this was a known Swift compiler issue that I was unaware of.

The solution is to remove the ‘nil’ and insert ‘[:]’ at line 19 in the SCNPhysicsShape initializer for the options argument:

private func setupPlane() {
        
    // create plane geometry with size and material properties
    let myPlane = SCNPlane(width: 10000.0, height: 10000.0)
    myPlane.firstMaterial!.diffuse.contents = NSColor.orange.cgColor
    myPlane.firstMaterial!.specular.contents = NSColor.white.cgColor
        
    // intialize noe
    let planeNode = SCNNode()
    // assign plane geometry to the node
    planeNode.geometry = myPlane
        
    // rotate -90.0 about the x-axis
    let rotMat = SCNMatrix4MakeRotation(-CGFloat(M_PI/3.0), 1.0, 0.0, 0.0)
    planeNode.transform = rotMat
    planeNode.position = SCNVector3Make(0.0, 0.0, 0.0)
        
    // setup the node's physics body property
    planeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: myPlane, options: [:]))
    planeNode.physicsBody!.categoryBitMask = PhysicsMask3DOF.plane.rawValue
        
    // add to scene
    sceneView.scene!.rootNode.addChildNode(planeNode)
}

Much thanks to mnuages for the quick answer.

 

UPDATE: This compiler issue is fixed in Xcode 8.