Swift:线程 1 在 class AppDelegate 中发出 SIGABRT 信号:UIResponder、UIApplicationDelegate
Swift: Thread 1 signal SIGABRT in class AppDelegate: UIResponder, UIApplicationDelegate
我正在学习教程,每次单击按钮时,我都会在 AppDelegate.swift 中收到一个错误,提示线程 1 信号 SIGABRT。
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //Thread 1 signal SIGABRT
这是我的故事板的屏幕截图。
我查看了所有内容,一些答案提到了一个不存在的 IBOutlet
连接,但正如您在屏幕截图中看到的,我的所有连接看起来都很好,所以我不知道问题出在哪里.
这是我的 viewController.swift 代码:
导入 UIKit
class ViewController: UIViewController {
@IBOutlet weak var input: UITextField!
@IBOutlet weak var label: UILabel!
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input, forKey: "myName")
input.text = " "
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidAppear(_ animated: Bool) {
if let x = UserDefaults.standard.object(forKey: "myName") as? String{
label.text = x
}
}
}
这是我在单击按钮时收到的完整错误消息:
2017-08-20 23:29:09.155350+0800 asd[2297:997880] [LayoutConstraints] 无法同时满足约束。
可能至少以下列表中的约束之一是您不想要的。
试试这个:
(1)查看每个约束并尝试找出您不期望的;
(2) 找到添加了不需要的约束或约束的代码并修复它。
(
“<_UILayoutSupportConstraint:0x608000284d30 _UILayoutGuide:0x7fc28340be50.height == 20 (active)>”,
“<_UILayoutSupportConstraint:0x608000283980 V:|-(0)-[_UILayoutGuide:0x7fc28340be50](活动,名称:'|':UIView:0x7fc28340b780)>”,
“<_UILayoutSupportConstraint:0x608000284dd0 _UILayoutGuide:0x7fc28340c420.height == 0 (active)>”,
“<_UILayoutSupportConstraint:0x608000284d80 _UILayoutGuide:0x7fc28340c420.bottom == UIView:0x7fc28340b780.bottom (active)>”,
"",
"",
"",
"",
"",
"",
"",
“”
)
将尝试通过打破约束来恢复
在 UIViewAlertForUnsatisfiableConstraints 处创建符号断点以在调试器中捕获此问题。
中列出的 UIView 的 UIConstraintBasedLayoutDebugging 类别中的方法也可能有帮助。
2017-08-20 23:29:11.137163+0800 asd[2297:997880] [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器是 /Users/Myeongjeon/Library/Developer/CoreSimulator/Devices/200D40A8-EFD4-4FE9-8E13-37C2E7D86BA6/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-08-20 23:29:11.137610+0800 asd[2297:997880] [MC] 从私人有效用户设置中读取。
2017-08-20 23:29:15.719443+0800 asd[2297:997880] [用户默认值] 尝试设置非 属性-list 对象;层 = > 作为键 myName 的 NSUserDefaults/CFPreferences 值
2017-08-20 23:29:15.723 asd[2297:997880] * 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'Attempt to insert non-property list object ; layer = > for key myName'
* 首先抛出调用栈:
(
0 CoreFoundation 0x0000000103725b0b exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010318a141 objc_exception_throw + 48
2 CoreFoundation 0x000000010378e625 +[NSException raise:format:] + 197
3 CoreFoundation 0x0000000103678729 _CFPrefsValidateValueForKey + 249
4 CoreFoundation 0x00000001036e5afc -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 572
5 CoreFoundation 0x000000010378fdaa-[CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 794
6 CoreFoundation 0x000000010374cc58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
7 CoreFoundation 0x0000000103678620 -[CFPrefsSource setValues:forKeys:count:] + 32
8 CoreFoundation 0x0000000103786af6 -[CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 454
9 CoreFoundation 0x000000010374cc58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
10 CoreFoundation 0x0000000103678620 -[CFPrefsSource setValues:forKeys:count:] + 32
11 CoreFoundation 0x00000001036bbfe9 -[CFPrefsSource setValue:forKey:] + 57
12 核心基础 0x0000000103788a4f __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 319
13 CoreFoundation 0x000000010378824d 归一化五元组 + 317
14 核心基础 0x0000000103788909 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 105
15 核心基础 0x0000000103772c15 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 261
16 核心基础 0x00000001036bbf34 _CFPreferencesSetAppValueWithContainer + 68
17 基金会 0x0000000102c89790 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 55
18 asd 0x0000000102bafc51 TFC3asd14ViewController6buttonfCSo8UIButtonT + 1073
19 asd 0x0000000102baff6a TToFC3asd14ViewController6buttonfCSo8UIButtonT + 58
20 UIKit 0x0000000103b4ad82 -[UIApplication sendAction:to:from:forEvent:] + 83
21 UIKit 0x0000000103ccf5ac -[UIControl sendAction:to:forEvent:] + 67
22 UIKit 0x0000000103ccf8c7 -[UIControl _sendActionsForEvents:withEvent:] + 450
23 UIKit 0x0000000103cce802 -[UIControl touchesEnded:withEvent:] + 618
24 UIKit 0x0000000103bb87ea -[UIWindow _sendTouchesForEvent:] + 2707
25 UIKit 0x0000000103bb9f00 -[UIWindow 发送事件:] + 4114
26 UIKit 0x0000000103b66a84 -[UIApplication sendEvent:] + 352
27 UIKit 0x000000010434a5d4 __dispatchPreprocessedEventFromEventQueue + 2926
28 UIKit 0x0000000104342532 __handleEventQueue + 1122
29 核心基金会 0x00000001036cbc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
30 核心基础 0x00000001036b10cf __CFRunLoopDoSources0 + 527
31 核心基础 0x00000001036b05ff __CFRunLoopRun + 911
32 核心基础 0x00000001036b0016 CFRunLoopRunSpecific + 406
33 图形服务 0x0000000107d05a24 GSEventRunModal + 62
34 UIKit 0x0000000103b49134 UIApplicationMain + 159
35 asd 0x0000000102bb1927 主 + 55
36 libdyld.dylib 0x0000000106d9a65d 开始 + 1
)
libc++abi.dylib:以 NSException
类型的未捕获异常终止
您的代码的严重错误在这里:
@IBOutlet weak var input: UITextField!
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input, forKey: "myName")
input.text = " "
}
您正在尝试将 input
保存到标准 UserDefaults
,但 input
是 UITextField
。您无法将 UITextField
保存到 UserDefaults
.
也许您想做这样的事情:
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input.text ?? "", forKey: "myName")
input.text = " "
}
调试输出中最重要的部分:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ; layer = > for key myName'
这是说您的代码正在尝试为键 myName
设置无效值。
有关约束的消息表明您的代码和故事板设置可能需要修复,但这不是崩溃的原因。
我正在学习教程,每次单击按钮时,我都会在 AppDelegate.swift 中收到一个错误,提示线程 1 信号 SIGABRT。
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //Thread 1 signal SIGABRT
这是我的故事板的屏幕截图。
我查看了所有内容,一些答案提到了一个不存在的 IBOutlet
连接,但正如您在屏幕截图中看到的,我的所有连接看起来都很好,所以我不知道问题出在哪里.
这是我的 viewController.swift 代码: 导入 UIKit
class ViewController: UIViewController {
@IBOutlet weak var input: UITextField!
@IBOutlet weak var label: UILabel!
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input, forKey: "myName")
input.text = " "
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidAppear(_ animated: Bool) {
if let x = UserDefaults.standard.object(forKey: "myName") as? String{
label.text = x
}
}
}
这是我在单击按钮时收到的完整错误消息: 2017-08-20 23:29:09.155350+0800 asd[2297:997880] [LayoutConstraints] 无法同时满足约束。 可能至少以下列表中的约束之一是您不想要的。 试试这个: (1)查看每个约束并尝试找出您不期望的; (2) 找到添加了不需要的约束或约束的代码并修复它。 ( “<_UILayoutSupportConstraint:0x608000284d30 _UILayoutGuide:0x7fc28340be50.height == 20 (active)>”, “<_UILayoutSupportConstraint:0x608000283980 V:|-(0)-[_UILayoutGuide:0x7fc28340be50](活动,名称:'|':UIView:0x7fc28340b780)>”, “<_UILayoutSupportConstraint:0x608000284dd0 _UILayoutGuide:0x7fc28340c420.height == 0 (active)>”, “<_UILayoutSupportConstraint:0x608000284d80 _UILayoutGuide:0x7fc28340c420.bottom == UIView:0x7fc28340b780.bottom (active)>”, "", "", "", "", "", "", "", “” )
将尝试通过打破约束来恢复
在 UIViewAlertForUnsatisfiableConstraints 处创建符号断点以在调试器中捕获此问题。 中列出的 UIView 的 UIConstraintBasedLayoutDebugging 类别中的方法也可能有帮助。 2017-08-20 23:29:11.137163+0800 asd[2297:997880] [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器是 /Users/Myeongjeon/Library/Developer/CoreSimulator/Devices/200D40A8-EFD4-4FE9-8E13-37C2E7D86BA6/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-08-20 23:29:11.137610+0800 asd[2297:997880] [MC] 从私人有效用户设置中读取。 2017-08-20 23:29:15.719443+0800 asd[2297:997880] [用户默认值] 尝试设置非 属性-list 对象;层 = > 作为键 myName 的 NSUserDefaults/CFPreferences 值 2017-08-20 23:29:15.723 asd[2297:997880] * 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'Attempt to insert non-property list object ; layer = > for key myName' * 首先抛出调用栈: ( 0 CoreFoundation 0x0000000103725b0b exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010318a141 objc_exception_throw + 48 2 CoreFoundation 0x000000010378e625 +[NSException raise:format:] + 197 3 CoreFoundation 0x0000000103678729 _CFPrefsValidateValueForKey + 249 4 CoreFoundation 0x00000001036e5afc -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 572 5 CoreFoundation 0x000000010378fdaa-[CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 794 6 CoreFoundation 0x000000010374cc58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264 7 CoreFoundation 0x0000000103678620 -[CFPrefsSource setValues:forKeys:count:] + 32 8 CoreFoundation 0x0000000103786af6 -[CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 454 9 CoreFoundation 0x000000010374cc58 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264 10 CoreFoundation 0x0000000103678620 -[CFPrefsSource setValues:forKeys:count:] + 32 11 CoreFoundation 0x00000001036bbfe9 -[CFPrefsSource setValue:forKey:] + 57 12 核心基础 0x0000000103788a4f __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 319 13 CoreFoundation 0x000000010378824d 归一化五元组 + 317 14 核心基础 0x0000000103788909 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 105 15 核心基础 0x0000000103772c15 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 261 16 核心基础 0x00000001036bbf34 _CFPreferencesSetAppValueWithContainer + 68 17 基金会 0x0000000102c89790 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 55 18 asd 0x0000000102bafc51 TFC3asd14ViewController6buttonfCSo8UIButtonT + 1073 19 asd 0x0000000102baff6a TToFC3asd14ViewController6buttonfCSo8UIButtonT + 58 20 UIKit 0x0000000103b4ad82 -[UIApplication sendAction:to:from:forEvent:] + 83 21 UIKit 0x0000000103ccf5ac -[UIControl sendAction:to:forEvent:] + 67 22 UIKit 0x0000000103ccf8c7 -[UIControl _sendActionsForEvents:withEvent:] + 450 23 UIKit 0x0000000103cce802 -[UIControl touchesEnded:withEvent:] + 618 24 UIKit 0x0000000103bb87ea -[UIWindow _sendTouchesForEvent:] + 2707 25 UIKit 0x0000000103bb9f00 -[UIWindow 发送事件:] + 4114 26 UIKit 0x0000000103b66a84 -[UIApplication sendEvent:] + 352 27 UIKit 0x000000010434a5d4 __dispatchPreprocessedEventFromEventQueue + 2926 28 UIKit 0x0000000104342532 __handleEventQueue + 1122 29 核心基金会 0x00000001036cbc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 30 核心基础 0x00000001036b10cf __CFRunLoopDoSources0 + 527 31 核心基础 0x00000001036b05ff __CFRunLoopRun + 911 32 核心基础 0x00000001036b0016 CFRunLoopRunSpecific + 406 33 图形服务 0x0000000107d05a24 GSEventRunModal + 62 34 UIKit 0x0000000103b49134 UIApplicationMain + 159 35 asd 0x0000000102bb1927 主 + 55 36 libdyld.dylib 0x0000000106d9a65d 开始 + 1 ) libc++abi.dylib:以 NSException
类型的未捕获异常终止您的代码的严重错误在这里:
@IBOutlet weak var input: UITextField!
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input, forKey: "myName")
input.text = " "
}
您正在尝试将 input
保存到标准 UserDefaults
,但 input
是 UITextField
。您无法将 UITextField
保存到 UserDefaults
.
也许您想做这样的事情:
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input.text ?? "", forKey: "myName")
input.text = " "
}
调试输出中最重要的部分:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ; layer = > for key myName'
这是说您的代码正在尝试为键 myName
设置无效值。
有关约束的消息表明您的代码和故事板设置可能需要修复,但这不是崩溃的原因。