Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

Getting error on retrieving data #12

Closed
kamalupasena opened this issue Mar 31, 2016 · 3 comments
Closed

Getting error on retrieving data #12

kamalupasena opened this issue Mar 31, 2016 · 3 comments

Comments

@kamalupasena
Copy link

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

@Oyvindkg
Copy link
Owner

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

@kamalupasena
Copy link
Author

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

@Oyvindkg
Copy link
Owner

Oyvindkg commented Apr 1, 2016

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

@Oyvindkg Oyvindkg closed this as completed Apr 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants