Storing bezier paths in Core Data for Mac OS X and iOS
I am developing an iOS application that comes pre-loaded with CoreData content.
I am trying to create an importer app for the Mac OS X command-line which uses the same xcdatamodel and imports the initial data that I can ship with the actual app.
So far, so good.
One of the fields in the model, however, is a transformable in which I want to store a Bezier path. Unfortunately, Mac OS X uses NSBezierPath while iOS uses UIBezierPath to store bezier paths.
Is there any way of using the binary UIBezierPath class (and its header file) from the iOS Simulator platform in my OS X project?
I don’t want to convert my project to run in the simulator because I want to be able to run it from the command-line and pass arguments. There should be a way to make this work, shouldn’t there? Because the simulator platform is compiled for the Mac’s architecture and no GUI components are ever used.I am also looking for other (creative?) ways to solve this problem… A custom NSValueTransformer, perhaps, or a reverse-engineering of UIBezierPath’s NSCoding adaptation?
Maybe I am just too narrow-minded, too focused on what will essentially turn out to be a futile attempt. Please feel free to point this out in your answer 开发者_运维百科if you think it’s the case…The library CKBezierPath emulates the NSBezierPath for iOS. Not tested, but give it a try. ;-)
Ken Ferry (Apple engineer from the Cocoa frameworks team):
The keyed archive container format is interchangeable, however whether a particular archive is interchangeable depends on what's in it. Obviously if a class is only present on one of iOS and Mac OS X, that's a problem. For arbitrary individual classes present on both OSes, it's difficult to say anything too concretely. People may have taken advantage of the new OS to drop some aspects of compatibility.
If your keyed archive contains exclusively Foundation classes, it's our intent that they should be as interchangeable between iOS and Mac OS X as between versions of Mac OS X. I don't think we have specific tests to make sure it works, though, so, well, if it doesn't for something, file a bug.
NSBezierPath
is AppKit though, so you have to fall back to reverse engeneering. It might not be too difficult because UIBezierPath
and NSBezierPath
probably both depend on CGPath, but that's only a guess.
精彩评论