此iOS Swift代码在运行时生成以下错误:
线程1:信号SIGBRT
任何人都可以帮我确定可能的原因和解决方案吗?
(注意:Amazon.com的网址仅为示例而硬编码。)
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
//Outlets erstellen
@IBOutlet var timer: WKInterfaceTimer!
@IBOutlet var slider: WKInterfaceSlider!
@IBOutlet var button: WKInterfaceButton!
//Outlet-Action, bei Änderung des Slider Werts
@IBAction func slider(_ value: Float) {
//Button kann genutzt werden
button.setEnabled(true)
//Text für den Button wird bestimmt
let roundedValue = Int(round(value))
UserDefaults.standard.setValue(roundedValue, forKey: "countdown")
let text: String = "FIRE (\(roundedValue)s)"
button.setTitle(text)
}
//Outlet-Action, wenn der Button gedrückt wird
@IBAction func fire(){
//Timer Farbe wird geändert, um diesen zu sehen
let swiftColor = UIColor(red: 1, green: 222, blue: 113, alpha: 1)
timer.setTextColor(swiftColor)
//Button wird deaktiviert + Button Text nun ...
button.setTitle("...")
button.setEnabled(false)
//Timer Wert abfragen
var countdown: Int = (UserDefaults.standard.value(forKey: "countdown")! as! Int)
//Timer starten
timer.setDate(NSDate(timeIntervalSinceNow: TimeInterval(countdown)) as Date)
timer.start()
//NSTimer mit 1 Sek Intervall
var clock = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: "countdown", userInfo: nil, repeats: true)
func countdown() {
countdown -= 1
if countdown == 4{
//HTTP-Request
var request = URLRequest(url: URL(string: "http://amazon.com")!)
request.httpMethod = "POST"
let session = URLSession.shared
session.dataTask(with: request) {data, response, err in
print("Entered the completionHandler")
}.resume()
//Timer auschalten
let schwarz = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
timer.setTextColor(schwarz)
//Button in Normalzustand
button.setTitle("FIRE (0s)")
button.setEnabled(true)
//Slider auf Standart
slider(0)
}
}
}
override func awake(withContext context: Any?) {
super.awake(withContext: context)
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
答案 0 :(得分:0)
Try cleaning your project. If that doesn't work, recreate any pod files that you may have created while making the project. Also, check if you have multiple outlets or actions for the same object.