Oyvindkg / swiftydb

💀Neither supported nor maintained for years. A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting error on retrieving data

kamalupasena opened this issue · comments

I am getting a error when i am using bool or integer as data type of a attributes , its save to the data without showing any errors but then i am trying to retrieve the data its give me a error saying NSUnknownKeyException this class is not key value coding-compliant for the key

this is my class

class Message: NSObject,Storable{

    let database: SwiftyDB! = SwiftyDB(databaseName: AppConfig.DATABASE_NAME)

    var id : String?
    var body : String?
    var status : String?
    var timestamp : String?
    var isHide : Bool?
    var location : String?
    var msgType : String?
    var roomId : String?
    var userId : String?

    override required  init() {
        super.init()
    }


    func saveMesssage(shouldUpdate: Bool = false, completionHandler: (success: Bool) -> Void) {
        database.asyncAddObject(self, update: shouldUpdate) { (result) -> Void in
            if let error = result.error {
                print(error)
                completionHandler(success: false)
            }
            else {
                completionHandler(success: true)
            }
        }
    }


}

can anybody tell me what i am doing wrong here

Hello!

Unfortunately, Swift properties aren't key value coding compliant, so all your property types needs to be representable in ObjC when retrieving objects.

Bool? is not a valid ObjC type. I would recommend using either NSNumber?, or Bool instead.

If you need Bool?, you can use dataForType: to get the objects as dictionaries. You can map the dictionary to your object manually, or by using a JSON mapping library. Both should be relatively straight forward :)

Hope this helps you sort it out :)

Edit:
Relevant documentation can be found here

Thank you i also have one other problem can we use DISTINCT , group by in swiftdb ?

No problem.

DISTINCT and GROUP BY are not supported yet. If you need them, please create issues requesting the features, and they will be added in a future update