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

Add dictionary representation to Objc models #67

Merged
merged 2 commits into from
Aug 10, 2017
Merged

Add dictionary representation to Objc models #67

merged 2 commits into from
Aug 10, 2017

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Jul 25, 2017

As we have a need internally at Pinterest for a dictionary representation I took a stab on #53. Resolves #51.

@matelo Did a great job lining up all the pieces to get this integration in, I think it's really close to get in, unfortunately it seems he's pretty busy, so hope we can push that over the finish line soonish.

Some changes to matelo's

  • Fixes error
  • Revert some not needed things
  • Update some code styles
  • Initialize NSNumbers with Literals

@rahul-malik We should think of also adding some tests that are testing our generated models. Maybe somehow in the integration tests. I thought around something like this:

NSDictionary *imageModelDictionary = @{
    @"height" : @(12),
    @"width" : @(11),
    @"url" : @"http://google.com"
};
Image *image = [[Image alloc] initWithModelDictionary:imageModelDictionary];
NSCAssert([imageModelDictionary isEqualToDictionary:[image dictionaryRepresentation]], @"Should be the same");


NSDictionary *userModelDictionary = @{
    @"id" : @(123),
    @"first_name" : @"Michael",
    @"last_name" : @"Schneider",
    @"image" : imageModelDictionary,
};
User *user = [[User alloc] initWithModelDictionary:userModelDictionary];
NSCAssert([userModelDictionary isEqualToDictionary:[user dictionaryRepresentation]], @"Should be the same");
var imageModelDictionary: [AnyHashable: Any] = ["height": (12), "width": (11), "url": "http://google.com"]
var image = Image(modelDictionary: imageModelDictionary)
XCTAssert(imageModelDictionary.isEqual(to: image.dictionaryRepresentation), "Image dictionary representation should be the same as the model dictionary.")

var userModelDictionary: [AnyHashable: Any] = ["id": (123), "first_name": "Michael", "last_name": "Schneider", "image": imageModelDictionary]
var user = User(modelDictionary: userModelDictionary)

XCTAssert(userModelDictionary.isEqual(to: user.dictionaryRepresentation), "User dictionary representation should be the same as the model dictionary")

@ghost
Copy link

ghost commented Jul 25, 2017

2 Warnings
⚠️ This is a big PR, please consider splitting it up to ease code review.
⚠️ Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.

Generated by 🚫 Danger

@rahul-malik rahul-malik merged commit 6808341 into pinterest:master Aug 10, 2017
@maicki maicki mentioned this pull request Aug 16, 2017
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

Successfully merging this pull request may close these issues.

Serialisation to JSON
2 participants