快速线程1信号sigabrt

时间:2018-12-19 14:54:48

标签: swift

所以我尝试使用apple Intro App开发来学习Swift ...在20.1节中,我们制作了Rock Paper Scissors应用,并在编写代码并运行它之后,在

上收到了此错误“线程1信号错误”。
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    return true
}

所以我尝试两次并继续给出此错误 我的Sign.swift代码是:

import Foundation
import GameplayKit
enum Sign {
    case Rock, Paper, Scissors
    var emoji : String {
        switch self {
        case .Rock:
            return ""
        case .Paper:
            return "✋"
        case .Scissors:
            return "✌️"
        }
    }
    func takeTurn(_ opponent: Sign) -> GameState {
        switch self {
        case .Rock:
            switch opponent{
            case .Rock:
                return GameState.Draw
            case .Paper:
                return GameState.Won
            case .Scissors:
                return GameState.Lose

            }
        case .Paper:
            switch opponent{
            case .Rock:
                return GameState.Lose
            case .Paper:
                return GameState.Draw
            case .Scissors:
                return GameState.Won
            }
        case .Scissors:
            switch opponent{
            case .Rock:
                return GameState.Lose
            case .Paper:
                return GameState.Won
            case .Scissors:
                return GameState.Draw
            }
        }
    }
    }

let randomChoice = GKRandomDistribution(lowestValue: 0, highestValue: 2)
func randomSign() -> Sign {
    let Sign = randomChoice.nextInt()
    if Sign == 0{
        return .Rock
    }else if Sign == 1{
        return .Paper
    }else{
        return .Scissors
    }
}

和GameState.swift是:

import Foundation
enum GameState {
    case Start, Won, Lose, Draw
}

和viewController.swift代码是:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        resetBoard()
    }
    @IBOutlet weak var computerEmoji: UILabel!
    @IBOutlet weak var gameStatus: UILabel!
    @IBOutlet weak var rockOut: UIButton!
    @IBOutlet weak var paperOut: UIButton!
    @IBOutlet weak var scissorsOut: UIButton!
    @IBOutlet weak var playAgainOut: UIButton!
    var currentGameState: GameState = GameState.Start
    func resetBoard(){
        computerEmoji.text = ""
        gameStatus.text = "Rock, Paper, Scissors?"
        rockOut.isHidden = false
        rockOut.isEnabled = true
        paperOut.isHidden = false
        paperOut.isEnabled = true
        scissorsOut.isHidden = false
        scissorsOut.isEnabled = true
        playAgainOut.isHidden = true

    }
    func play(_ playerTurn: Sign) {
        rockOut.isEnabled = false
        paperOut.isEnabled = false
        scissorsOut.isEnabled = false
        let opponent = randomSign()
        computerEmoji.text = opponent.emoji
        let currentGameState = playerTurn.takeTurn(opponent)
        switch currentGameState {
        case .Draw:
            gameStatus.text = "It's a Draw."
        case .Lose :
            gameStatus.text = "Sorry you Lose."
        case .Won :
            gameStatus.text = "You Win!!"
        case .Start :
            gameStatus.text = "Rock, Paper, Scissors?"
        }
        switch playerTurn {
        case .Rock:
            rockOut.isHidden = false
            paperOut.isHidden = true
            scissorsOut.isHidden = true
        case .Paper:
            rockOut.isHidden = true
            paperOut.isHidden = false
            scissorsOut.isHidden = true
        case .Scissors:
            rockOut.isHidden = true
            paperOut.isHidden = true
            scissorsOut.isHidden = false
        }
        playAgainOut.isHidden = false
    }
    @IBAction func rockSelected(_ sender: Any) {
        play(Sign.Rock)
    }
    @IBAction func paperSelected(_ sender: Any) {
        play(Sign.Paper)
    }
    @IBAction func scissorsSelected(_ sender: Any) {
        play(Sign.Scissors)
    }
    @IBAction func playAgainOut(_ sender: Any) {
        resetBoard()
    }
}

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

这名评论为“ shravani”的人是对的,我更改了操作按钮的名称,从而导致崩溃,因此我断开了较旧的名称,也连接了外侧按钮并正常工作