drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

UIImage Transformables disappearing #248

Closed susiej closed 7 years ago

susiej commented 7 years ago

IOS 10 swift 3 Hi, I've been using transformables to save UIImage thumbnails. These all disappeared when I installed ensembles, and after adding them back they seem to stay for a while, then disappear again (I assume when it resyncs). For larger files I am saving as Binary Data with external storage which so far works fine. Other transformables that just contain a small amount of data seem to also be working fine. I haven't sync'd to any other devices, it's just on my Iphone so far, as I'm just trying to get this half working correctly first. I didn't want the thumbnails to be saved externally as I wanted them to be accessed quickly as they are the main images in a long table. Looking in the db on my phone, all the items in the thumbnail column seem to have been set to null.

Is there a size limit for fields that can be synced? Is there anything else I may have missed? I'm completely new to Ensembles. Thanks

drewmccormack commented 7 years ago

Hi Susie, I’m not 100% what is wrong here, but I don’t think UIImage is a good transformable to use. It doesn’t seem to conform to NSCoding, so you would at the very least have to make your own transformer. Did you do that? Also, if you ever make a Mac app, you can’t import your data (no UIImage). My suggestion is to store as PNG data. UIImage has a method to get the PNGData, and you can put that on disk. You could even make a transformer that simply extracts the PNG, or uses it to make a UIImage. Hope that helps. Kind regards, Drew

On 30 Nov 2016, at 09:00, Susie Johnston notifications@github.com wrote:

I just tried installing on a second device, and it first had an empty database, and when I restarted the program it crashed at: BOOL passedChecks = [revisionManager checkRebasingPrerequisitesForEvents:eventsToMerge error:&error]; EXEC_BAD_ACCESS in the rebaseWithCompletion function.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263807669, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuAFW5zsQr81wCqvLUSxiFcxENE7V8ks5rDS0JgaJpZM4K_4sv.

drewmccormack commented 7 years ago

For completeness, here is a value transformer I found:

https://github.com/BendingSpoons/teleporter-lib-iOS/blob/master/Teleporter/NSValueTransformer%2BUIImage.m https://github.com/BendingSpoons/teleporter-lib-iOS/blob/master/Teleporter/NSValueTransformer+UIImage.m

Kind regards, Drew

On 30 Nov 2016, at 09:00, Susie Johnston notifications@github.com wrote:

I just tried installing on a second device, and it first had an empty database, and when I restarted the program it crashed at: BOOL passedChecks = [revisionManager checkRebasingPrerequisitesForEvents:eventsToMerge error:&error]; EXEC_BAD_ACCESS in the rebaseWithCompletion function.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263807669, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuAFW5zsQr81wCqvLUSxiFcxENE7V8ks5rDS0JgaJpZM4K_4sv.

susiej commented 7 years ago

I had written a transformer class (well, based off other peoples) to transform the UIImage which had been working fine before. I'll switch to storing just the data. I hadn't yet looked at a Mac version of my app, but plan to at some stage (data entry would be much easier). I didn't know you couldn't use UIImage for the Mac, so that is really good to know. Thanks :) Maybe I'll disable ensembles temporarily, then copy my backup database back to my phone, copy the images into a separate column as png/jpg, disable the old column, then try again with ensembles. Thanks for your help :)

drewmccormack commented 7 years ago

OK. Best to try to delete any cloud data you have before starting to sync again.

Drew

On 30 Nov 2016, at 09:41, Susie Johnston notifications@github.com wrote:

I had written a transformer class (well, based off other peoples) to transform the UIImage which had been working fine before. I'll switch to storing just the data. I hadn't yet looked at a Mac version of my app, but plan to at some stage (data entry would be much easier). I didn't know you couldn't use UIImage for the Mac, so that is really good to know. Thanks :) Maybe I'll disable ensembles temporarily, then copy my backup database back to my phone, copy the images into a separate column as png/jpg, disable the old column, then try again with ensembles. Thanks for your help :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263815064, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuACC6SosgrloifltM0ywcjBJs7Ym6ks5rDTa2gaJpZM4K_4sv.

drewmccormack commented 7 years ago

Out of interest, what were you transforming the UIImage to exactly? Ensembles can only handle NSData for a transformable. Core Data may be a bit more lenient, I’m not sure.

Drew

On 30 Nov 2016, at 09:41, Susie Johnston notifications@github.com wrote:

I had written a transformer class (well, based off other peoples) to transform the UIImage which had been working fine before. I'll switch to storing just the data. I hadn't yet looked at a Mac version of my app, but plan to at some stage (data entry would be much easier). I didn't know you couldn't use UIImage for the Mac, so that is really good to know. Thanks :) Maybe I'll disable ensembles temporarily, then copy my backup database back to my phone, copy the images into a separate column as png/jpg, disable the old column, then try again with ensembles. Thanks for your help :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263815064, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuACC6SosgrloifltM0ywcjBJs7Ym6ks5rDTa2gaJpZM4K_4sv.

susiej commented 7 years ago

Just as Data. I think I may have originally had it as NSData, but when it upgraded to swift 3 it converted to Data. This particular class I originally basically just copied from examples as it was the first transformable I've used. A lot of the thumbnails were generated from jpgs that had been scraped (so far haven't looked much into legal issues of scraping...), which is why they are jpegrepresentation. Is there an advantage of using pngs instead? Here is my transformer class:

class ImageTransformer: ValueTransformer {

override class func allowsReverseTransformation() -> Bool {
    return true
}

override class func transformedValueClass() -> AnyClass {
    return Data.self as! AnyClass
}

override func transformedValue(_ value: Any?) -> Any? {
    if let image = value as? UIImage {
        return UIImageJPEGRepresentation(image, 1.0)
    }
    return nil
}

override func reverseTransformedValue(_ value: Any?) -> Any? {
    if let data = value as? Data {
        return UIImage(data: data)
    }
    return nil
}

}

susiej commented 7 years ago

Where do you delete the cloud data (without deleting local data)? I have about 200 entries in my db which I really don't want to have to add back in manually.

drewmccormack commented 7 years ago

JPEG should be OK, but I have a feeling UIImage(data:) will not recognize it properly without a jpeg extension. That may be the problem you were having. I think you would need to write the data to file, and use a jpeg extension. PNG should just work regardless. It is basically the native format.

Drew

On 30 Nov 2016, at 10:36, Susie Johnston notifications@github.com wrote:

Just as Data. I think I may have originally had it as NSData, but when it upgraded to swift 3 it converted to Data. This particular class I originally basically just copied from examples as it was the first transformable I've used. A lot of the thumbnails were generated from jpgs that had been scraped (so far haven't looked much into legal issues of scraping...), which is why they are jpegrepresentation. Is there an advantage of using pngs instead? Here is my transformer class:

class ImageTransformer: ValueTransformer {

override class func allowsReverseTransformation() -> Bool { return true }

override class func transformedValueClass() -> AnyClass { return Data.self as! AnyClass }

override func transformedValue(_ value: Any?) -> Any? { if let image = value as? UIImage { return UIImageJPEGRepresentation(image, 1.0) } return nil }

override func reverseTransformedValue(_ value: Any?) -> Any? { if let data = value as? Data { return UIImage(data: data) } return nil } }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263826547, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuANn99sVlHi_5JO4AopMU32KrZs9xks5rDUOHgaJpZM4K_4sv.

drewmccormack commented 7 years ago

Best way to clear all data is to deleech on the device, and then use the iCloud Settings to delete the cloud data in iCloud Drive for you app.

That should leave your local data intact on the iPhone. Later, when you start syncing again, it should upload the data again.

Drew

On 30 Nov 2016, at 10:48, Susie Johnston notifications@github.com wrote:

Where do you delete the cloud data (without deleting local data)? I have about 200 entries in my db which I really don't want to have to add back in manually.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/248#issuecomment-263829358, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEuAG231x267ALHEepOkUFAG1ftP1Mbks5rDUZtgaJpZM4K_4sv.