3

in my app, I want to load certain image user picks, make some modification, after that, save a copy in my own file format. Since I want to keep track of user modification, I decided to export my file as a package(bundle).

So, in my document class, there's a NSImage object that holds the image file. In the fileWrapperOfType:error: method, I've setup a NSFileWrapper object, and put the object in it. Here's the code:

NSDictionary *fileWrappers = [self.documentFileWrapper fileWrappers];
if (image != nil) {
    NSBitmapImageRep *imageRep = [image bitmapImageRepresentation];
    NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:nil];
    NSFileWrapper *imageFileWrapper = [[NSFileWrapper alloc]
                                       initRegularFileWithContents:imageData];
    [imageFileWrapper setPreferredFilename:@"image"];

    [[self documentFileWrapper] addFileWrapper:imageFileWrapper];
}

return self.documentFileWrapper;

In my project plist file, I have two document types, first is the type of public.image since I need to load images in my app:

enter image description here

The other one is my own document type. To make the file a package, I've checked the bundle checkbox in xcode:

enter image description here

If I simply run this now, the code compains that finding extension from type identifier is deprecated, so, I managed to add an entry in Exported UTIs:

enter image description here

At this moment, everything seems working, except that the outputed folder with mdc extension, is indeed a folder instead of a package, what am I missing here? Thanks in advance!

2 Answers 2

2

Finally I solved the problem, the key here is to change Conforms To field to com.apple.package.

2
  • 1
    I have set "Comforms To" as com.apple.package, but it also outputed as a folder, not a package. I don't know why? I'm using Swift 2.0 and Xcode 7.3.
    – yangsibai
    Jul 5, 2016 at 16:33
  • After added an image document type like yours, it was working. I don't know why.
    – yangsibai
    Jul 5, 2016 at 16:52
0

In order for a package on OS X to be a pkg, it must have a .pkg extension. I hope it is as simple as having the wrong extension.

Note: Until recently, .pkg files were merely directories. Now, we often see package.pkg packages that are obscured cannot be browsed causually without some tricks like using Pacifist, pkgutil or xar:

pkgutil --extract file.pkg folder/

or

xar -xf file.pkg

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.