Start a new topic

Crash on invalid value to initialize object of type "StringValue" on Kinvey 3.10.1 for iOS

Hi, I was creating a data model class like the one in guideline for Kinvey 3.10.1 for iOS. 
It crashes on the reason: 

*** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value '11111' to initialize object of type 'StringValue': missing key 'value''

As you can see, in the Address class I have a list to store an array of string. Do I create this list variable correctly? I saw my array get stored on Kinvey, but it got crashed when trying to access the values on my device.

Thanks

class Post: Entity {
    @objc dynamic var address: Address?
    
    override class func collectionName() -> String {
        return "posts"
    }
    
    override func propertyMapping(_ map: Map) {
        super.propertyMapping(map)
        address <- ("address", map["address"])
    }
    
}

class Address: Object, Mappable {
    @objc dynamic var city: String?
    @objc dynamic var state: String?
    @objc dynamic var country: String?
    let list = List<StringValue>()
    
    convenience required init?(map: Map) {
        self.init()
    }
    
    func mapping(map: Map) {
        city <- ("city", map["city"])
        state <- ("state", map["state"])
        country <- ("country", map["country"])
        list <- ("list", map["list"])
    }
}

Victor,

  1. Does you code work if you pass a string (i.e. "hello") instead of '11111'?
  2. Can you try following method:
    let x : Int = 42
    var myString = String(x)

    and pass myString to address.list.append(myString).

Please send your sample project if above suggestions don't work.


Thanks,
Pranav

 

Hi, the following is my code when I created an entry in the collection

As you can see, I append an StringValue object to the list. I even used StringValue.init("11111") or simly "11111", but it still crashed with the same reason.

And Kinvey's version I'm using right now is 3.11. Actually 3.10.1 and 3.11 will both crash.


Thanks

        let address = Address()
        address.city = "NYC"
        address.state = "NY"
        address.country = "USA"
        address.list.append(StringValue("11111"))
        address.list.append(StringValue("22222"))
        newPost.address = address
        postStore.save(newPost) {}

 

Victor,

Looks like you are attempting to store an integer (11111) in an object of type 'StringValue'.
  1. Does you code work if you pass a string instead of '11111'?
  2. Have you tried typecasting like 'String(11111)' i.e. converting your integer to a string before saving/fetching?

Also, please upgrade to the latest Kinvey iOS SDK at the following URL and let me know if it makes any difference.

https://devcenter.kinvey.com/ios/downloads

 

Let me know if above suggestions help.


Thanks,

Pranav

Kinvey

Login or Signup to post a comment