简体   繁体   中英

Error when fetching data from Firebase (Swift 4)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM