Skip to content

objectWithClassName:dictionary: wasn’t encoding the dictionary into PFOject properly #947

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

Conversation

kangaroo5383
Copy link
Contributor

Date type properties are not being converted.

more details here:
#945

@ghost
Copy link

ghost commented Jun 24, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

@kangaroo5383 kangaroo5383 changed the title The method wasn’t encoding the dictionary into PFOject properly objectWithClassName:dictionary: wasn’t encoding the dictionary into PFOject properly Jun 24, 2016
@ghost
Copy link

ghost commented Jun 24, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ghost ghost added the CLA Signed label Jun 24, 2016
@nlutsenko
Copy link
Contributor

The problem with this approach is that this constructor should mutate the object and keep it dirty, whilst using mergeAfterSaveWithResult:decoder: will treat the object as fully coming from server and not dirty.
The approach that I would recommend is decoding all the keys in the dictionary recursively and then setting the keys instead of going through mergeAfterSave.
This will also fix the failing tests.

@nlutsenko
Copy link
Contributor

Let me know what you think about using that approach. Requesting changes so it's back into your queue, since it's failing tests...

@kangaroo5383
Copy link
Contributor Author

Thanks @nlutsenko that makes sense, I'll make the change.

@@ -1634,7 +1634,9 @@ + (instancetype)objectWithClassName:(NSString *)className {

+ (instancetype)objectWithClassName:(NSString *)className dictionary:(NSDictionary *)dictionary {
PFObject *object = [self objectWithClassName:className];
[object _mergeAfterSaveWithResult:dictionary decoder:[PFDecoder objectDecoder]];
[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
object[key] = [[PFDecoder objectDecoder] decodeObject:obj];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can save some method invocations by using a single local variable for storing the decoder. Feel free to leave as is, as it's super nitpicking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 nitpicking is important, shouldn't have missed that, my bad. Didn't think it should be __block since we're not modifying the var. Thanks for the quick feedback.

Copy link
Contributor

@nlutsenko nlutsenko Jun 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, shouldn't be __block, as it doesn't' change by the block.
Looks great now.

@nlutsenko nlutsenko self-assigned this Jun 24, 2016
@nlutsenko
Copy link
Contributor

Awesome, this is good to go, just need for all the tests to finish running...

@nlutsenko nlutsenko merged commit 2f70f59 into parse-community:master Jun 25, 2016
@nlutsenko nlutsenko added the type:bug Impaired feature or lacking behavior that is likely assumed label Jun 25, 2016
@nlutsenko nlutsenko added this to the 1.14.0 milestone Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants