adamwulf / JotUI

OpenGL based drawing view built for and used by Loose Leaf for iPad
http://getlooseleaf.com/opensource/
MIT License
268 stars 28 forks source link

export as NSData #42

Closed abrpatel closed 5 years ago

abrpatel commented 5 years ago

Hi Adam,

I'm trying to save / reload the drawings with core data using NSData. I know that its relying on the documents directory now, but I can't quite figure out how to manage implementation of the NSData Persistence.

As its creator, any tips or advice would be appreciated.

I love what you've created so far. Amazing creativity and generosity.

Thank You!

adamwulf commented 5 years ago

The three objects sent to the completion handler of [JotView exportImageTo:andThumbnailTo:andStateTo:withThumbnailScale:onComplete:] are the same object that are written to disk in the private method [JotView exportImageTo:andThumbnailTo:andStateTo:andJotState:withThumbnailScale:onComplete:]. You can delete the disk writing operations there, and then save those three objects (UIImage* ink, UIImage* thumb, JotViewImmutableState* state) however you'd like to core data.

Then on load, create a subclass of JotViewStateProxy and hydrate it from whatever you've loaded from core data. Passing that JotViewStateProxy subclass into [JotView loadState:] should load in just fine.

You'll need to:

  1. modify JotViewImmutableState to return the NSCoding-safe dictionary from writeToFile: instead of writing it, then save that result however you'd like
  2. subclass JotViewStateProxy to load in whatever you just saved and send that to loadState:

Glad you're enjoying JotUI! and glad to hear it's been helpful!

abrpatel commented 5 years ago

Success!! Get a huge NSData file, but I'm able to save and reload from it. Would you like to create a PR for it?

adamwulf commented 5 years ago

Glad you got it working!

and Yes that'd be awesome for the PR! As long as it retains backwards compatibility and still adds support for optional NSData saving, that'd be awesome :)

abrpatel commented 5 years ago

actually not fully working. I'm running into the following issues when I try to reload the data: should be this: IMG_2150

but I'm getting this: IMG_2149

I'll create a PR of what I've got so far in a few minutes, so hopefully you can see the process on your end.

abrpatel commented 5 years ago

figured it out! Updating the PR in a few. Your initial advice was very helpful. The key was saving the NSData from the dictionary that was created in write to disk function. Unfortunately, I can't seem to make it backwards compatible, as you'll see.