3lvis / Sync

JSON to Core Data and back. Swift Core Data Sync.
MIT License
2.55k stars 263 forks source link

Sync export skips over well defined Transformable Attributes #591

Open ghost opened 3 years ago

ghost commented 3 years ago

Trying to define array in core data that will import / export with Sync. Defined attribute arrays as per core data documentation. The transformable attributes work fine in my app. They are just failing to import / export. Does Sync handle Transformable data.

Method #1) Loading data into core data . . .

    let newLocation = IARLocation(context: context)
    newLocation.uniqueID = UUID().uuidString
    newLocation.textDescription = "location 1"
    let gpsLocation: [Double] = [Double(1.0), Double(1.3)]
    newLocation.gps = gpsLocation
    newLocation.gpsLatitude = 1.0
    newLocation.gpsLongitude = 1.3

Method #1) Export output for Location entity . . .

"location": { "gps_latitude" = 1; "gps_longitude" = "1.3"; "location_image" = { "image_filename" = "5BBD3652-0D52-41AD-A744-78CB9CBF9D83"; "image_path" = ""; "image_type" = png; name = locationImage; "text_description" = "Location Image"; "unique_id" = "5BBD3652-0D52-41AD-A744-78CB9CBF9D83"; };

Method #1) Core Data def attached location core data def.png

Method #2) Loading data into core data . . .

    let newAddress = IARAddress(context: context)
    newAddress.uniqueID = UUID().uuidString
    newAddress.textDescription = "address 1"
    let gpsAddress: [NSNumber] = [NSNumber(5.0), NSNumber(5.8)]
    newAddress.gps = gpsAddress
    newAddress.gpsLatitude = 5.0
    newAddress.gpsLongitude = 5.8
    newAddress.city = "Whoville"
    newAddress.zipcode = "00000"
    newAddress.state = "WV"
    newAddress.apartment = "3C"
    newAddress.street = "Main"
    newAddress.number = "140303"
    newDoor.address = newAddress

Method #2) Export output for Location entity . . .

    address =         {
        apartment = 3C;
        city = Whoville;
        "gps_latitude" = 5;
        "gps_longitude" = "5.8";
        name = address;
        number = 140303;
        state = WV;
        street = Main;
        "text_description" = "address 1";
        "unique_id" = "91B70457-33DE-48F8-925A-67C6E0C09B58";
        zipcode = 00000;
    };

Method #2) Core Data def attached address core data def.png

I currently have gpsLatatude and gpsLongitude defined as Doubles in my code data entity attributes just for verification purposes. I would much prefer to use transformable arrays.

Address core data def Location core data def

3lvis commented 3 years ago

Oh, sorry about this. I merged a PR recently trying to fix some warnings. I see what the problem was. I’m not at home at the moment but will rollback as soon as I can.

ghost commented 3 years ago

Thank you

3lvis commented 3 years ago

Reverted!

3lvis commented 3 years ago

@richard-hood-motorola-solutions could you double-check if it works now?

3lvis commented 3 years ago

I think I reacted too quickly and you are actually referring to a different issue.

I currently have gpsLatatude and gpsLongitude defined as Doubles in my code data entity attributes just for verification purposes. I would much prefer to use transformable arrays.

I assume your GPS will be a list of doubles but I don't understand how come Latitude and longitude can be arrays?

If you want to store multiple points into one entity doesn't it make more sense to store an array of dictionaries then you can have a latitude and longitude per entry?

The other option is to make a GPSEntity that stores latitude and longitude then you can have a one-to-many relationship between IARLocation and GPSEntity but I don't recommend this. It's better to keep your structure as flat as possible.

Feel free to write me directly https://twitter.com/3lvis

ghost commented 3 years ago

Attached is a project that illustrates that Sync is not exporting Transformable attributes.

gpsDict is defined as a Dictionary [String:Double] in the data model custom class field gpsDouble is defined as an Array of doubles [Double] in the data model custom class field primes is defined as an Array of ints [Int] in the data model custom class field textTest is defined as an Array of Strings [String] in the data model custom class field

All of which can be accessed in the app as defined but none of which get exported, as is shown in the debug console when you hit the export button. Sync export just seems to skip over those attributes defined as Transformable.

(You may have to hit the export button twice. There seems to be some delay in the DB being updated.)

All of these Transformable types should be exportable, shouldn't they?

Richard Hood Richard.hood@motorolasolutions.com SyncTest.zip