'Command CompileSwift failed with a nonzero exit code' IN SWIFT

I want to program a macOS game in Swift. When I try to run the program, this error is displayed:

Command CompileSwift failed with a nonzero exit code

I have inquired about various websites (especially stackoverflow.com) but have not found a solution. Although there are already questions about this error message, but none could solve my problem.


Here is my code:

GameScene.swift :

import SpriteKit

class GameScene: SKScene, SKPhysicsContactDelegate {

    override func didMove(to view: SKView) {

        physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
        physicsWorld.gravity = CGVector(dx: 0, dy: 0)
        physicsWorld.contactDelegate = self

        let object: SKSpriteNode = SKSpriteNode(color: NSColor.red, size: CGSize(width: 20, height: 20))

        object.zPosition = 0
        object.physicsBody = SKPhysicsBody(rectangleOf: object.size)
        object.physicsBody?.mass = 0
        object.position = CGPoint(x: size.width / 2, y: size.height / 2)

        addChild(object)

    }

}

ViewController.swift :

import Cocoa
import SpriteKit

class ViewController: NSViewController {

    override func viewDidLoad() {

        let skview: SKView = view as! SKView

        skview.showsNodeCount = false
        skview.showsFPS = false

        skview.presentScene(GameScene(size: view.bounds.size))

    }

}

Does anyone have an solution?

enter image description here,

enter image description here