FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

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 Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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

Reply to this topic…

You need to create an account or log in to reply.

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.