views:

29

answers:

1

I've got to be missing something simple, but Google is not helping.

My file saves and loads fine. (I've overridden dataOfType to get some stuff in it.) Then I override fileWrapperOfType (in preparation for creating a bundle), and I get a "The document 'Untitled' could not be saved as 'test'." sheet when I try to save. Even when I empty out my method to the absolute most basic form I can think of...

- (NSFileWrapper*)fileWrapperOfType:(NSString*)typeName error:(NSError**)outError
{
  NSFileWrapper* worldWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];
  return [worldWrapper autorelease];
}

...I still can't save. What am I missing?

+1  A: 

From the docs (emphasis mine):

The dictionary must contain entries whose values are the file wrappers that are to become children and whose keys are filenames.

You use nil so my guess is that worldWrapper is nil, and returning nil is interpreted as not being able to save your file.

Johan Kool
Close; I had checked to be sure that worldWrapper was non-nil (and it was). But this answer did prompt me to try using an empty dictionary rather than a nil one, and that worked. This still seems very unusual, though; don't most methods allow a nil dictionary in place of an empty one?
andyvn22
@andyvn22: Some methods do, some don't. It's becoming increasingly common that you need to pass an empty value of the desired type (dictionary, string, array, etc.) rather than nil, so it's generally a good idea to do that even if you're not sure it's necessary.
Chuck