Swift3 是什么导致了“a”;SIGABRT“;Xcode 8.3中的AppDelegate文件出错?
@UIApplicationMain 类AppDelegate:UIResponder,UIApplicationLegate{//线程1:信号SIGABRTSwift3 是什么导致了“a”;SIGABRT“;Xcode 8.3中的AppDelegate文件出错?,swift3,sigabrt,xcode8,Swift3,Sigabrt,Xcode8,@UIApplicationMain 类AppDelegate:UIResponder,UIApplicationLegate{//线程1:信号SIGABRT var window: UIWindow? “线程1:信号SIGABRT”位于“类”行的末尾 总结 用户输入膳食小计、小费百分比和税收百分比;程序输出税额、小费金额和膳食总成本。这是一个简单的单视图程序。我没有对AppDelegate文件进行任何更改。所有代码都添加到ViewController文件中 AppDelegate文件中没有其
var window: UIWindow?
“线程1:信号SIGABRT”位于“类”行的末尾
总结
用户输入膳食小计、小费百分比和税收百分比;程序输出税额、小费金额和膳食总成本。这是一个简单的单视图程序。我没有对AppDelegate文件进行任何更改。所有代码都添加到ViewController文件中
AppDelegate文件中没有其他错误。ViewController文件中有几个警告,但没有错误。在运行时,模拟器(iPhone 7)显示但为空。控制台输出位于ViewController代码之后
ViewController的代码:
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var txtMealCost: UITextField!
@IBOutlet var txtTipPercent: UITextField!
@IBOutlet var txtTaxRatePercent: UITextField!
@IBOutlet weak var lblTaxAmt: UILabel!
@IBOutlet weak var lblTipAmt: UILabel!
@IBOutlet weak var lblTotalCost: UILabel!
/* var mealCost = Double(txtMealCost.text)
var tipPercent : Float = 0
var taxRatePercent : Float = txtTaxRatePercent.text
var taxAmt : Float = 0
var tipAmt : Float = 0
var totalCost : Float = 0
var totalCost = mealCost + taxAmt + tipAmt
*/
@IBAction func btnCalculate(_ sender: UIButton) {
var mealCost = Double(txtMealCost.text!)!
var tipPercent = Double(txtTipPercent.text!)!
var taxRatePercent = Double(txtTaxRatePercent.text!)!
var taxAmt = mealCost * taxRatePercent
var lblTaxAmt = String(taxAmt)
var tipAmt = mealCost * tipPercent
var lblTipAmt = String(lblTipAmt)
var totalCost = mealCost + taxAmt + tipAmt
var lblTotalCost = String(totalCost)
/* var fMealCost = (mealCost as NSString).floatValue
var fTipPercent = tipPercent
var fTaxRatePercent = taxRatePercent
var fTaxAmt = taxAmt
var fTipAmt = tipAmt
*/ // var fTotalCost = totalCost
}
@IBAction func Clear(_ sender: UIButton) {
txtMealCost.text = ""
txtTipPercent.text = ""
txtTaxRatePercent.text = ""
lblTaxAmt.text = ""
lblTipAmt.text = ""
lblTotalCost.text = ""
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
控制台输出:
2017-04-19 14:10:54.720 MealCostCalculator[1932:96055]*由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:::]:此类不符合key MealCost的键值编码。”
*第一次抛出调用堆栈:
(
0 CoreFoundation 0x000000010ccf4b0b异常预处理+171
1 libobjc.A.dylib 0x000000010a085141 objc_异常_抛出+48
2 CoreFoundation 0x000000010ccf4a59-[N异常提升]+9
3基金会0x000 000 0109B9EA8B-[ NSKORKS(NSKEY ValueCoDIN)SETValue:FordK::+ 292)
4 UIKit 0x000000010a6f2644-[UIViewController设置值:forKey:+87
5 UIKit 0x000000010a95f6b9-[UIRuntimeOutletConnection connect]+109
6 CoreFoundation 0x000000010cc9ae8d-[NSArray makeObjectsPerformSelector:+269
7 UIKit 0x000000010a95e06f-[UINib实例化所有者:选项:][1856
8 UIKit 0x000000010a6f8c73-[UIViewController\u loadViewFromNibNamed:bundle:][381
9 UIKit 0x000000010a6f9589-[UIViewController loadView]+177
10 UIKit 0x000000010a6f98ba-[UIViewController loadViewIfRequired]+195
11 UIKit 0x000000010a6fa10a-[UIViewController视图]+27
12 UIKit 0x000000010a5c263a-[UIWindow AddRootViewControllerServiceWifPossible]+65
13 UIKit 0x000000010a5c2d20-[UIWindow\u setHidden:强制:][294
14 UIKit 0x000000010a5d5b6e-[UIWindow makeKeyAndVisible]+42
15 UIKit 0x000000010a54f31f-[UIApplication\u callInitializationDelegatesForMainScene:transitionContext:+4346
16 UIKit 0x000000010a555584-[UIApplication\u在主场景中运行:transitionContext:completion:+1709
17 UIKit 0x000000010a552793-[UIApplication WorkspaceDiEndTransaction:][182
18 FrontBoardServices 0x000000010e4045f6 FBSSERIALQUEUE正在呼叫A区块+24
19 FrontBoardServices 0x000000010e40446d-[FBSSerialQueue\u performNext]+186
20 FrontBoardServices 0x000000010e4047f6-[FBSSerialQueue\u performNextFromRunLoopSource]+45
21 CoreFoundation 0x000000010cc9ac01CFRUNLOOP\u正在调用\u OUT\u以执行\u源0\u功能+17
22 CoreFoundation 0x000000010cc800cf\uuu CFRunLoopDoSources0+527
23 CoreFoundation 0x000000010cc7f5ff\uuu CFRunLoopRun+911
24 CoreFoundation 0x000000010cc7f016 CFRunLoopRunSpecific+406
25 UIKit 0x000000010a55102f-[UIApplication_run]+468
26 UIKit 0x000000010a5570d4 UIApplicationMain+159
27计量计算器0x0000000109aa9487主+55
28 libdyld.dylib 0x000000010dc9465d启动+1
29???0x0000000000000001 0x0+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)
在此处输入代码
检查您的故事板是否有一个名为“MealCost”的插座。也许它应该是“txtMealCost”。别介意。我发现了错误,现在程序运行了。