Why am I getting NSUnkownKeyException? - ios

I have looked at the answers of this question here and none of them seem to fix the problem I am having, also most other answers are not for swift but i tried the ones I understood.
All of the class names match, the outlets have the right names and there are no outlets that aren't defined... no little yellow triangle. (links to images below, site wont let me put more than 2)
Shows class names in inspector and file are the same
Shows outlet names in file and inspector

As the screenshot clearly shows, the property MyInputText does not bind to anything. Did you connect the UITextField in the UIStoryBoard to the related property in the code?
Here a screenshot showing a proper binding between a property and the XIB object.
Here a screenshot showing a proper binding between a property and the XIB object.

Related

IBOutlet says connected in StoryBoard, but not in code

Not sure what the problem is here, I've tried:
Cleaning, rebooting Xcode/Computer
Clearing Derived Data
Relinking outlets
I don't have this problem with any other outlets in any other views. Here are some photos:
https://imgur.com/a/2t3da
https://imgur.com/a/zikBq
EDIT: It was a really silly mistake -> misspelled the identifier in my tableView method. Thanks for all your help though!
Did you set your custom cell class in Identity Inspector?
Identity Inspector
Did you try delete outlet and drag outlet again?
Are you referencing to correct custom class? Double check this. I am often using another class unwillingly and than I realized that I am in wrong file.
I think its a normal behaviour, try loading your VC in the storyboard and add the assistant editor on the right. Mine does the exact same thing when i go to my code straight without loading the VC in the storyboard. Can you also show how you set the textLabel?

Swift PNChart PNCircleChart with Storyboard

I'm trying to set up a basic PNChart PNCircleChart on my app. I created a UIView in the storyboard and set the class to PNCircleChart. The restoration ID is piechart. I created an outlet in to my view controller that looks like:
#IBOutlet weak var pie: PNCircleChart!
Now I'm trying to build a basic piechart in my viewdidload and I can't figure out how.
pie.backgroundColor = UIColor.greenColor()
pie.setValue(50, forKey: "A")
pie.setValue(50, forKey: "B")
pie.strokeChart()
It is failing with a NSUnkownKeyException error. Any idea how to do this in swift
The NSUnknownKeyException is almost always caused when one of your interface elements was hooked up to a property in your view controller that you then deleted. The property was deleted from the view controller, but the interface builder was never unhooked from that property.
The actual exception message should tell you what "key" it's having trouble finding, which should give you a hint as to which UI element is hooked up wrong.
Once you figure out which key is hooked up wrong, go through your UI elements and right click on each of them. One of them will be hooked up to a property of this name (and it won't exist in your class source code file). You need to either click the X for this connection to delete the connection, or you need to add the property back to your source code file.

Where do I detect where the outlet is from in Xcode?

I downloaded a project from GitHub and I'm experiencing some problems when detecting where a referencing outlet comes from.
This is an UIImage called "backgroundImage".
This is a UIViewController called "WalkthroughPageContentViewController".
"backgroundImages" has two outlets references, one of which is connected to the "WalkthroughPageContentViewController" UIViewController.
But there isn't any #IBOutlet connection here.
So where does the first referencing outlet come from?
I had a quick look at this project, and the answer is that the referencing outlet doesn't come from anywhere. It's broken. If you examine the destination, the you'll see that Xcode knows this is a problem:
And if you open up the WalkthroughPageContentViewController.swift file, and add an outlet called backgroundImage, then close and reopen the file, you'll find it's magically been linked back up to the Storyboard:
So, I'd surmise that at some point, there was an outlet in the file called backgroundImage, which was hooked up to the Storyboard, but then it was later deleted, leaving the project in this state.
This is pretty common when editing projects in Xcode. The Storyboard connections are basically just stored in XML in the .xib file, and there's no magic two-way connection between them and the code at design time, so if you delete the lines of code that they point to, you'll end up in this state.

Can't add a new view in a storyboard without getting an not key value compliant message

I'm getting the "not key-value coding compliant message".
I've had this several times in the past and know what it means and have always been able to resolve it, but I don't know why I'm getting it in this instance. All I've done is:
1) drag n drop a UILabel onto the main view:
2) Drag from the UILabel to view controller and get IB to insert and connect an outlet:
But when I run I get "this class is not key value coding-compliant for the key currentStatus.'"
Here's the connections:
Why is it not working, what is missing?
What you have shown is ok, check if you removed some outlet properties from your code file (.h) and forgot to remove their links from IB.

additional NIB for view controller in tabbed app

{Xcode 4.2, deployment target iOS4.3, not storyboard, using ARC}
I started with a tabbed application template & chose the universal platform, which nicely gives me view controller classes & NIB files for an iPhone (ClassName_iPhone.xib) & an iPad (ClassName_iPad.xib) for 2 tabs, with an if statement in the AppDelegate to determine which to run - exactly how I wanted it set up.
I wanted to add a 3rd & 4th tabs, so starting with the 3rd tab (doing 1 at a time) I created a new UIViewController subclass. As it doesn't give the option to create both NIBs at once, I selected "Targeted for iPad", & had intended to create the iPhone NIB manually. I added a "_iPad" suffix to the created NIB file, then I created a user interface view NIB file to which I added the "_iPhone" suffix. I then set up the code for the new view controller in the AppDelegate implementation file to include the 3rd view controller & tab, & I used the other view controller classes as a guide to set up the new class's code.
For the 3rd _iPhone NIB, I dragged a view object from the objects library onto the canvas, & set it up as per the other 2 _iPhone NIBs. But when I went to connect the outlets, there is no view outlet in the referencing outlets of the connections panel to connect with, which I thought there should be. At this point I suspected something was wrong.
I tried running it in the simulator, in iPad mode it works fine (all 3 tabs are clickable). But in iPhone mode clicking the 3rd tab crashes it with a "SIGABRT" on thread 1. It's obvious what I did didn't work. I don't see anything in the output window that gives me any clues.
Being a newbie to obj-c, so not being too sure of the problem, I would have thought that I either:
have used the wrong user interface template (view)
should have used a view controller object from the object library
(not a view)
or that I should have declared some outlets in my view controller
class files.
But if I should have done either of the latter 2, then my question would be why does the iPad NIB work then, when it clearly has a view object in the NIB & no outlets declared in the class files (same with the other 2 view controllers for both devices)?
Does the UITabView class somehow have outlets pre-declared within it for the first 2 tabs? But that still doesn't explain why the _iPad NIB works.
As usual, any help & advice much appreciated, & if there's a link to an explanation somewhere that I've missed, please show me, because I'm happy to do the research.
If what I've done wrong here is not determinable, then I guess ultimately what I'm asking is a clue to how best to create the second NIB file for iPhone to mesh with the class created with iPad NIB.
Sorry to answer my own question but with further searching I found this answer that was the solution, although not quite the whole story. So I thought to put what I did in an asnwer so others can refer to it.
As Piotr Czapla explains in the linked answer, for some reason Xcode doesn't populate the connectionRecords data, as you can see by my first red arrow. Having a look at the view controller that works (where second red arrow is), that's what the data should look like. So the answer is to cut the data & paste it into the NIB file, or type it. You can do this in Xcode by right-clicking the NIB file in the project navigatior & then Open As > Source Code, which is what you see in my screenshots.
The bit I want to add to Piotr Czapla's explanation though is the destination reference pointed to by the second red arrow might not be correct for the NIB file you're pasting into (mine wasn't) & Xcode might not let you go back into IB mode. If so, you need to get the correct reference from the IBUIView class within your NIB file, as pointed to by the third red arrow. Once I copied that reference to my destination reference ref=, as shown by the fourth red arrow, all was ok & the problem was solved. I could then go back into IB mode (right click, Open As > Interface Builder - iOS) & the view works in the simulator.

Resources