I created a document-based application that uses Core Data. First I created the Mac version, and now that it works correctly, I’m moving on to creating the iOS version.
I just can't figure out how to maximize code reuse between iOS / mac versions in relation to the Core data bit, since they don't use the same classes.
My document class that handles persistence is a subclass of NSPersistentDocument . My intention is that a well-designed model class should work in both environments, especially since I don’t do everything that is very bizarre with basic data.
Now, as NSPersistentDocument available in iOS, I hit the wall. I tried to get around this using #if TARGET_OS_MAC and TARGET_OS_IPHONE and thereby make it a subclass of UIManagedDocument in the iOS version. That would obviously be convenient, but I can't get it to work like that. And it really looks pretty dirty, since there is a lot of other material that should also be conditional.
I also tried to build the atop classes of NSDocument / UIDocument , instead I implement Core data bindings myself, but it also looks pretty confusing, and I don't think this is the right way.
Question:
It seems like a good idea to me to reuse the same class of documents between versions of iOS / mac, but maybe I'm naive.
What is the best way to do this?
Should I forget about code sharing and create a separate document class for the iOS version that emulates all the methods that are present in the Mac version?
Frost source share