Reputation: 58672
I tried to compile my first iOS Hello app.
ViewController.swift
//
// ViewController.swift
// My First Project
import UIKit
class ViewController: UIViewController {
// Declare components
@IBOutlet weak var inputLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func submitBtn(_ sender: Any) {
inputLabel.text = "Hello World"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
getting Build Succeeded
But after about 5 seconds, I got this
0x0000000103915f69 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x000000010770f723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000010770f59c -[FBSSerialQueue _performNext] + 189
20 FrontBoardServices 0x000000010770f925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000105ff0311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x0000000105fd559c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x0000000105fd4a86 __CFRunLoopRun + 918
24 CoreFoundation 0x0000000105fd4494 CFRunLoopRunSpecific + 420
25 UIKit 0x00000001039147e6 -[UIApplication _run] + 434
26 UIKit 0x000000010391a964 UIApplicationMain + 159
27 My First Project 0x0000000102e6db3f main + 111
28 libdyld.dylib 0x0000000106f7868d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I used to have this
I updated to this
Re-run and still happening ...
Re-run and still happening ...
Upvotes: 13
Views: 12409
Reputation: 8493
This happened to me because I was copying some files from another project (and renaming them). Xcode got confused and apparently struggled with connecting outlets. In Xcode everything looked fine, but I was stuck with the same error as in the question on runtime, with no further explanation.
I fixed it by cleaning the project and deleting derived data. As always.. :/
Upvotes: 0
Reputation: 3060
This problem happens when you delete referencing outlet in your ViewController
and forget to remove the connection from storyboard
.
Perfect connection ✅
The perfect referencing outlet looks like below screenshot.
Now let's delete the referencing outlet from
.h
file
Problem ⚠️
if we remove referencing outlet from .h
file Xcode will give warning in Storyboard. this is the trick you can find which outlet was deleted from the class.
i hope this will help you .
Solution
In your case you may have changed the name lable
to inputLable
so you need to do :
Remove the connection to label
.
Re-Connect the controller to inputLabel
.
Upvotes: 6
Reputation: 625
Others have mentioned about outlets and its references which you have to make sure about them that they have connected correctly in to your class.
Another possible case comes to my mind may be this : If you have define a key path for your label under user defined Rundtime Attributes
in the identity inspector
tab in storyboard, and if the key is undefined, you will get this message error in your console log :
...this class is not key-value compliant for the key label.
e.g. in the image below you see a key path popupTitle
if it is not defined in your class of label it will get this error message. and in some cases it will crash. Make sure you don't have extra key path in this section.
Upvotes: 1
Reputation: 769
Issue is in your labels, I am 100% sure you have deleted some outlet references and forget to remove the connection from story board. Please check
Upvotes: 12
Reputation: 553
It crashed because you removed your IBOutlet
label
in your code of ViewController.swift
without removing the connection
on Storyboard.
@IBOutlet weak var label: UILabel!
To solve this problem, right click on inputLabel
in storyboard
, click the 'x' button at label
connection like this:
Note: Please don't forget remove the connection in storyboard before removing your IBOutlet in code.
Upvotes: 1
Reputation: 285082
There is an inconsistency in code and screenshot.
label.text = "Hello World"
inputLabel.text = "Hello World"
The error message is :
... is not key-value compliant for the key label.
So most likely in your actual code the IBOutlet
is named inputLabel
but in Interface Builder there is a (dead) connection to label
which causes the crash.
Solution:
Main.storyboard
in the navigation bar and ViewController
in the canvas. label
.inputLabel
.Upvotes: 2
Reputation: 11
Make sure the storyboard elements are connected to the outlets in your code. Try to delete all the connections in the connections inspector and reconnect the elements
When you go to main.storyboard, on the right you have a panel, the most right one os the connections inspector. In there you have to delete al the connection by pressing the little 'x' in the connections.
It should look somewhat familiar like this, but different names in this screenshot
delete all of them
also in your viewController.swift file, remove all the @IBOutlet lines.
Then connect your outlets again to your ViewController.swift file, which you did before
For just changing a label in code it finally should look like this final screenshot
mind the outlet on the right
I hope this will help you!
Upvotes: 1