I'm following a tutorial and every time I click the button I get an error in AppDelegate.swift that says Thread 1 signal SIGABRT.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //Thread 1 signal SIGABRT
Here's a screenshot of my storyboard.
I have looked all over and some answers refer to an IBOutlet
connection that doesn't exist but as you can see in the screenshot all my connections look good so I don't know what the problem is.
here's my viewController.swift code: import 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
}
}
}
here's the complete error message that I get when I click the button: 2017-08-20 23:29:09.155350+0800 asd[2297:997880] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<_UILayoutSupportConstraint:0x608000284d30 _UILayoutGuide:0x7fc28340be50.height == 20 (active)>", "<_UILayoutSupportConstraint:0x608000283980 V:|-(0)-[_UILayoutGuide:0x7fc28340be50] (active, names: '|':UIView:0x7fc28340b780 )>", "<_UILayoutSupportConstraint:0x608000284dd0 _UILayoutGuide:0x7fc28340c420.height == 0 (active)>", "<_UILayoutSupportConstraint:0x608000284d80 _UILayoutGuide:0x7fc28340c420.bottom == UIView:0x7fc28340b780.bottom (active)>", "", "", "", "", "", "", "", "" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2017-08-20 23:29:11.137163+0800 asd[2297:997880] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /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] Reading from private effective user settings. 2017-08-20 23:29:15.719443+0800 asd[2297:997880] [User Defaults] Attempt to set a non-property-list object ; layer = > as an NSUserDefaults/CFPreferences value for key myName 2017-08-20 23:29:15.723 asd[2297:997880] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ; layer = > for key myName' * First throw call stack: ( 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 CoreFoundation 0x0000000103788a4f __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 319 13 CoreFoundation 0x000000010378824d normalizeQuintuplet + 317 14 CoreFoundation 0x0000000103788909 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 105 15 CoreFoundation 0x0000000103772c15 -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 261 16 CoreFoundation 0x00000001036bbf34 _CFPreferencesSetAppValueWithContainer + 68 17 Foundation 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 sendEvent:] + 4114 26 UIKit 0x0000000103b66a84 -[UIApplication sendEvent:] + 352 27 UIKit 0x000000010434a5d4 __dispatchPreprocessedEventFromEventQueue + 2926 28 UIKit 0x0000000104342532 __handleEventQueue + 1122 29 CoreFoundation 0x00000001036cbc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 30 CoreFoundation 0x00000001036b10cf __CFRunLoopDoSources0 + 527 31 CoreFoundation 0x00000001036b05ff __CFRunLoopRun + 911 32 CoreFoundation 0x00000001036b0016 CFRunLoopRunSpecific + 406 33 GraphicsServices 0x0000000107d05a24 GSEventRunModal + 62 34 UIKit 0x0000000103b49134 UIApplicationMain + 159 35 asd 0x0000000102bb1927 main + 55 36 libdyld.dylib 0x0000000106d9a65d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
What's critically wrong with your code is here:
@IBOutlet weak var input: UITextField!
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input, forKey: "myName")
input.text = " "
}
You are trying to save input
into the standard UserDefaults
, but input
is a UITextField
. You cannot save UITextField
into UserDefaults
.
Maybe you want to do something like this:
@IBAction func button(_ sender: UIButton) {
label.text = input.text
UserDefaults.standard.set(input.text ?? "", forKey: "myName")
input.text = " "
}
The most important part in your debug output:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ; layer = > for key myName'
It is saying that your code is trying to set an invalid value for the key myName
.
Messages about constraints suggests your code and storyboard settings may need to be fixed, but it is not the cause of the crash.