Question

I would like to share a common document format between iOS and OSX. Note that this is not an MDI application; there will ever be one document to save/load. NSDocument style user driven management (e.g.. Save, Save As, Open etc.) is not required.

The biggest challenge is there seems to be no common document encoding format naturally compatible with OSX and IOS (yet). According to Document-Based Application Programming Guide for iOS, it looks like encoding/decoding conversion is required between NSDocument and UIDocument derived classes. I wish there is a universal serialization mechanism compatible with all devices across Apple ecosystem. Any thoughts, ideas, tips are appreciated in this regard.

Can I use a UIDocument derived class in my mac osx application and the document becomes compatible with IOS?

Was it helpful?

Solution

No, you can't use or subclass UIDocument in a Cocoa application because UIDocument doesn't exist in Cocoa.

In both NSDocument and UIDocument, you determine the format that you will use. So, just implement them both to use the same format for the output and the input.

It wouldn't be too hard to use the preprocessor to set up a file-pair that implements a subclass of NSDocument when building for the Mac and UIDocument when building for iOS. This would prevent you from having mismatched serialization and deserialization implementations, since you'd have only one copy of each and be using it on both platforms.

OTHER TIPS

Peter's answer above is correct, but I have a suggestion that does not involve the C pre-processor (not available in Swift) that is a bit more Cocoa-like.

Watch WWDC 2014 session 233 to set up your iOS and Mac apps in a single Project as separate targets, then use Categories on your document class to implement the common functionality:

CommonFunctions.h    

@interface AppDocument (CommonFunctions)
- (void)function;
@end

-

CommonFunctions.m

@implementation AppDocument (CommonFunctions)

- (void) function {
      /// stuff here
}

@end

Your AppDocument class would have 2 different classes inheriting from UI/NSDocument as necessary for each platform/target, and each target would pull in the categories from a common place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top