UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on 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.

Thanks

3      

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()
items.append(item)
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.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot 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.