0

i try to fetch data from firebase to my ios tableView. this is my function to fetchadata enter image description here I have create a NewWord class in model folder. enter image description here

when i run it show the error

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key vietnam.'

Really Appreciate if anyone can help. thanks

  • Did you have an `IBOutlet` named `vietnam` that you deleted after from your code? That particular error usually occurs when you have an outlet connected from your storyboard to your code but the variable in code doesn't exist anymore. You should check your connections. (P.S: I know, this has nothing to do with the code you provided but it could be a cause) – Alejandro Iván May 04 '18 at 03:51
  • @AlejandroIván he needs to put at objc before his class variables when inheriting from NSObject – Lance Samaria May 04 '18 at 11:17
  • @LanceSamaria oh yeah, I completely ignored the `NSObject` part. Thanks! – Alejandro Iván May 04 '18 at 13:35

1 Answers1

0

Here's the answer right here from @matt: SO Answer

From @matt: In Swift 4, Objective-C cannot see your instance properties unless you expose them explicitly.

Put @objc before your class properties:

class NewWord: NSObject {
    @objc var vietnam: String?
    @objc var example: String?
    @objc var explanation: String?
    @objc var vietnam: String?
}

Or you can do it this way SO Answer from @AshvinGudaliya.

Add @objcMembers before the class declaration:

@objcMembers class NewWord: NSObject {
    var vietnam: String?
    var example: String?
    var explanation: String?
    var vietnam: String?
}

I would link this as a duplicate but I don't know how to do that plus there are 2 different ways you can go about resolving this.

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256