Skip to content

PFObject's objectWithClassName:dictionary: not doing the right thing with dates #945

@kangaroo5383

Description

@kangaroo5383

Example input dictionary:

{
    "confirmationId": "AWKMhXX",
    "data" :  {
        "bookingType": "LB_Access_Entry";
        "units": 1,
        "user" : {
            "name": "new entry person"
        }
    },
    "loungeId": "LB_HQ",
    "reservationTime":{
        "__type":"Date",
        "iso": "2016-06-22T01:37:00.000Z"
    }
}

Running it through + (instancetype)objectWithClassName:(NSString *)className dictionary:(NSDictionary *)dictionary

Output:

<LBReservation: 0x7f8132d22850, objectId: new, localId: (null)> {
    confirmationId = AWKMhXX;
    data =     {
        bookingType = "LB_Access_Entry";
        units = 1;
        user =         {
            name = "new entry person";
        };
    };
    loungeId = "LB_HQ";
    reservationTime =     {
        "__type" = Date;
        iso = "2016-06-22T01:37:00.000Z";
    };
}

Note - reservationTime is just saved as a dictionary instead of converted to NSDate as expected.

There's a straightforward fix of changing its implementation to:

+ (instancetype)objectWithClassName:(NSString *)className dictionary:(NSDictionary *)dictionary {
    return [self _objectFromDictionary:dictionary defaultClassName:className completeData:YES];
}

instead of using a naive assignment as it is doing right now

[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        object[key] = obj;
    }];

If there aren't any other considerations that I somehow missed I can make a PR with those changes.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions