Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash by accessing enum field after deserialising snapshot #191

Closed
hiroshitazawa opened this issue Dec 7, 2017 · 2 comments
Closed

Crash by accessing enum field after deserialising snapshot #191

hiroshitazawa opened this issue Dec 7, 2017 · 2 comments

Comments

@hiroshitazawa
Copy link

hiroshitazawa commented Dec 7, 2017

I have a query with the following GraphQLEnumType.

enum FeatureClass {
    person
    car
    cat
    dog
  }

When I run apollo-codegen, I get the following enum definition and it works fine.

public enum FeatureClass: String, Apollo.JSONDecodable, Apollo.JSONEncodable {
  case person = "person"
  case car = "car"
  case cat = "cat"
  case dog = "dog"
}

public var classes: [FeatureClass] {
  get {
    return snapshot["classes"]! as! [FeatureClass]
  }
  set {
    snapshot.updateValue(newValue, forKey: "classes")
  }
}

However, I serialise the snapshot data using JSONSerializationFormat, save it in NSUserDefault, deserialise it and access the field of the enum again, I get the following crash.

someData.classes (Crash)

Could not cast value of type 'NSTaggedPointerString' (0x110dde5c8) to 'XXX.FeatureClass' (0x106d48600)

I personally investigated the issue of this field by accessing through snapshot dictinary and found that casting the certain enum type is making the crash.

po someData.snapshot["classes"]! as! [FeatureClass] (Crash)

However, if I access the enum field as the array of enum.rawValue, it works fine.

po someData.snapshot["classes"]! as! [FeatureClass.RawValue] (Works)

Is this the expected behaviour ?.
I am using apollo-codegen 0.17.1 (not latest). I can't use the latest apollo-codegen for some enum naming issues.

Thanks in advance.

@hiroshitazawa
Copy link
Author

hiroshitazawa commented Dec 10, 2017

I just found the solution about this issue. It was related to this previous post. #51

If I construct the deserialised dictionary with Something.Data(jsonObject:), then, it works fine.
I close this issue post.

@bhgupta01
Copy link

I just found the solution about this issue. It was related to this previous post. #51

If I construct the deserialised dictionary with Something.Data(jsonObject:), then, it works fine.
I close this issue post.

thanks @hiroshitazawa you saved my day 🙇‍♀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants