Start a new topic

Kinvey.error invalidOperation

when trying to download a collection from kinvey I get the error "(Kinvey.error) invalidOperation and descriptive string is: "invalid entity creation: ... " 

This happens after Kinvey has successfully established a sharedClietn with my appkey and appsecret and I call the function:

 

dataStore?.find(){(result: Result<AnyRandomAccessCollection<myObject>, Swift.Error>) in switch result {

        case .success(let vocabularies): ...


case .failure(let error):

print("Error: \(error)")


So, I am not actually doing much except trying to access and find my collection.


Anyone has an idea, why?


  


Hi Arnold,


Have you updated the model class of your collection to use "Swift.Codable" pattern as explained here?

Are you using the latest version (v3.23.0) of the iOS SDK?


Thanks,

Pranav

Kinvey


Dear Pranav, 

thank you for your reply. was in China and had no mac with me. 

I am trying to verify the issue now but running in the homebrew / outdated git version problem described e.g. here: 

https://stackoverflow.com/questions/44840351/pod-init-creates-error-that-says-you-need-at-least-git-version-1-8-5-to-use-c

https://github.com/Homebrew/legacy-homebrew/issues/30180

but could not resolve that issue yet, hence still need some time. 

Will write here again, once I could test and (probably) update to newest kinvey version

Arnold

Dear Pranav, 

I had some issues with the git version but was able solve those and updated all my pods, also Kinvey. 

Kinvey is now at 3.24.0. 

However even after product cleaning and closing reopening Xcode I get a lot of errors of the type:


Value of optional type 'String?' must be unwrapped to a value of type 'String'


It is a total of 14 errors, 4 in the Persistable.swift, 3 in the PushOperation.swift, 2 in the FileStore.swif 1 each in the Query.Swift, HttpRequest.swift, MIC.swift, ObjectMapperJSONParser.swift. 

Hi Arnold,


Thanks for all the details. I am looking into this. Please answer the following questions:

  1. What version of the Xcode you are using?
  2. Which version of cocoapods are you running? When you run `pod --version` in the terminal, what do you get?



Thanks,

Pranav

Kinvey

Dear Pranav, 


Xcode is version> 10.2.1

Cocoapods is version> 1.4.0

Hello Arnold,


I think you are seeing those errors because you are using an old version of the CocoaPods which does not includes the changes for Xcode 10.2 and Swift 5. Please try installing the latest version using "gem install cocoapods --pre". You can always check which version is the latest and when they were released using this link: https://github.com/CocoaPods/CocoaPods/releases. I am using v1.7.0.beta.3. Once the CocoaPods in updated then please run "pod install" again and let me know if it fixes the issue.


Thanks,

Pranav

Kinvey

Dear Pranav, 

thank you for your patience, really. 

as you correctly suggested, updating to the newest version of cocoapods fixed the issues I described in my posting four days ago. 

However, that brings me right back to the original error, aka invalid entity creation.


I also had the codable included in my object class as you described. 



  

import Foundation
import Kinvey
import ObjectMapper

class BVBVocabulary: Entity, Codable{
    
    var vocID : Int?
    @objc dynamic var targetLanguage : String?
    @objc dynamic var targetArea : String?
  ...
    var vocUpdatedAt : Int64?
    
    override class func collectionName() throws -> String{
        //to return the backend collection name of kinvey for this object class
        return "vocabulary"  
    }

    //Map properties in your backend collection to the members of this entity
    enum CodingKeys : String, CodingKey {
        case vocID = "vocNo"
        case targetLanguage = "targetLanguage"
      ...
        case vocUpdatedAt = "vocUpdatedAt"
    }
    
    //Swift.Decodable
    required init(from decoder: Decoder) throws {
        //This maps the "_id", "_kmd" and "_acl" properties
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        vocID = try container.decodeIfPresent(Int.self, forKey: .vocID)
        targetLanguage = try container.decodeIfPresent(String.self, forKey: .targetLanguage)
      ...
       vocUpdatedAt = try container.decodeIfPresent(Int64.self, forKey: .vocUpdatedAt)
        
    }
    
    // Swift.Encodable
    override func encode(to encoder: Encoder) throws {
        //This maps the "_id", "_kmd" and "_acl" properties
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        //Each property in your entity should be mapped using the following scheme:
        //try container.encodeIfPresent(<#property#>, forKey: .<#CodingKey property name#>)

        try container.encodeIfPresent(Constants.KinveyBackendKeys.vocID, forKey: .vocID)
        try container.encodeIfPresent(Constants.KinveyBackendKeys.targetLanguage, forKey: .targetLanguage)
      ...
        try container.encodeIfPresent(Constants.KinveyBackendKeys.vocUpdatedAt, forKey: .vocUpdatedAt)
    }
    
    ///Default Consructor
    required init() {
        super.init()
    }
    
    /// Realm Constructor
    required init(realm: RLMRealm, schema: RLMObjectSchema) {
        super.init(realm: realm, schema: schema)
    }
    /// Realm Constructor
    required init(value: Any, schema: RLMSchema) {
        super.init(value: value, schema: schema)
    }
    
    @available(*, deprecated, message: "Please use Swift.Codable instead")
    required init?(map: Map) {
        super.init(map: map)
    }
    
    @available(*, deprecated, message: "Please use Swift.Codable instead")
    override func propertyMapping(_ map: Map) {
      //required for Kinvey
        super.propertyMapping(map)
        
        vocID <- (Constants.KinveyBackendKeys.vocID, map[Constants.KinveyBackendKeys.vocID])
        targetLanguage <- (Constants.KinveyBackendKeys.targetLanguage, map[Constants.KinveyBackendKeys.targetLanguage])
...     
 vocUpdatedAt <- (Constants.KinveyBackendKeys.vocUpdatedAt, map[Constants.KinveyBackendKeys.vocUpdatedAt])
        
    }
   
}
 

 I included the codable object class above. of course there are more object variables but for ease of viewing I omitted all but three variables (... marks the omitted variables) 


Login or Signup to post a comment