Ios 应用程序崩溃,即使除了使用Swift 2的Xcode中的代码之外什么都没有

Ios 应用程序崩溃,即使除了使用Swift 2的Xcode中的代码之外什么都没有,ios,swift,debugging,uicolor,sigabrt,Ios,Swift,Debugging,Uicolor,Sigabrt,我试过很多不同的方法,也研究了很多,但我似乎无法解决这个问题 下面的代码编译得很好,构建成功,但几秒钟后,Xcode将打开AppDelegate文件,并打开经典线程1信号SIGABRT,应用程序不工作 顺便说一句,该应用程序不应该做任何复杂的事情,而应该只是更改背景色的颜色 请让我知道,我可以如何改变它,使它更好 import UIKit class ViewController: UIViewController { func changeBackround() {

我试过很多不同的方法,也研究了很多,但我似乎无法解决这个问题

下面的代码编译得很好,构建成功,但几秒钟后,Xcode将打开
AppDelegate
文件,并打开经典线程1信号SIGABRT,应用程序不工作

顺便说一句,该应用程序不应该做任何复杂的事情,而应该只是更改
背景色的颜色

请让我知道,我可以如何改变它,使它更好

import UIKit

class ViewController: UIViewController {
    func changeBackround() {
        self.view.backgroundColor = UIColor.randomColor()
    }
    override func viewDidLoad() {
        NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("changeBackground"), userInfo: nil, repeats: true)   
    }    
}

extension UIColor {
    static func randomColor() -> UIColor {
        let red = CGFloat(drand48())
        let green = CGFloat(drand48())
        let blue = CGFloat(drand48())
        return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
    }
}

将函数名
changeBackround
拼写错误,在您放置的选择器中(“changeBackround”)
,错误是因为它没有找到与选择器对应的函数

试试这个

import UIKit

class ViewController: UIViewController {


    func changeBackground() {
        self.view.backgroundColor = UIColor.randomColor()
    }

    override func viewDidLoad() {

        NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("changeBackground"), userInfo: nil, repeats: true)

    }

}

extension UIColor {
    static func randomColor() -> UIColor {
        let red = CGFloat(drand48())
        let green = CGFloat(drand48())
        let blue = CGFloat(drand48())
        return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
    }
}

将函数名
changeBackround
拼写错误,在您放置的选择器中(“changeBackround”),错误是因为它没有找到与选择器对应的函数

试试这个

import UIKit

class ViewController: UIViewController {


    func changeBackground() {
        self.view.backgroundColor = UIColor.randomColor()
    }

    override func viewDidLoad() {

        NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("changeBackground"), userInfo: nil, repeats: true)

    }

}

extension UIColor {
    static func randomColor() -> UIColor {
        let red = CGFloat(drand48())
        let green = CGFloat(drand48())
        let blue = CGFloat(drand48())
        return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
    }
}
请参阅以了解如何调试崩溃。然后使用相关详细信息更新您的问题,包括完整的错误消息,并指出导致崩溃的确切代码行。请参阅以了解如何调试崩溃。然后用相关详细信息更新您的问题,包括完整的错误消息,并指出导致崩溃的确切代码行。