NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

This class is not key value coding-compliant?

Forums > macOS

My environment is as follows: macOS Catalina Xcode 12 StoryBoard Single Window/View Controller - the view controller has custom code to populate a tableView in the View Controller The tableView has 7 columns and is populated from a SQLite table. The tableView displays data for 6 of the 7 columns. On the last column I get the following error: valueForUndefinedKey:]: this class is not key value coding-compliant for the key itemUsedLast.

I have searched for information on this error and what I have found is it seems to be saying that for the field itemUsedLast can not find an outlet? But in the case for a tableview the only IBOutlet is one for the entire tableView. Also, the identifiers in the storyboard match the code in the custom view controller.

I have completed several tableViews before and have not run into this issue.

I have tried several remedies but none resolved this issue.

Any thoughts on how to debug this further or resolve this will be appreciated.



This is resolved. The problem was a mis-match in the names in NSObject, field identifiers and IB.

So as an example.

class Item: NSObject {
    @objc   var itemNumber: String? = ""
    @objc   var itemLastused: Date?

var items:[Item] = []
let item = Item()
item.itemNumber = "100"
item.itemLastused = Date()
let valueForNumberKey = items[0].value(forKey: "itemNumber")
let valueForDateKey = items[0].value(forKey: "itemLastused

Besides the names matching here they also need to match in the IB.


Hacking with Swift is sponsored by MadMachine

SPONSORED Want to explore your Swift skill outside of the Apple world? Join the MadMachine community and start to program microcontrollers in Swift.

Get it now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.