writeToURL:ofType:typeName error:

Discussion in 'Mac Programming' started by MrFusion, Dec 29, 2008.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    Hi,

    Instead of letting cocoa take care of saving and loading documents, I want to do it myself (because I want to start using file packages). I played around with this a long time ago, but alas I can not find that project anymore. I think I used writetofile back then without much problems. But that function has been deprecated.

    According to the documentation I should use writeToURL and readfromurl.

    But whatever I do, I always gets this error:
    The document “Untitled” could not be saved as “Untitled”. The file does not exist.

    I am playing around in a new project, so this is all the code there is.
    While it doesn't actually do anything, I say everything is fine, so there shouldn't be any errors presented to the user?
    At least that's what I remember from long ago. Overwrite the methods, do nothing in them, return allok and run the program. Open and save will do nothing.

    Maybe I should use override other methods?
    I want to use a filepackage and have full control over reading and writing. Create a dir and write my files in it.

    Code:
    - (id)init
    {
        self = [super init];
        if (self) {
        
            // Add your subclass-specific initialization here.
            // If an error occurs here, send a [self release] message and return nil.
        
        }
        return self;
    }
    
    - (NSString *)windowNibName
    {
        // Override returning the nib file name of the document
        // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
        return @"MyDocument";
    }
    
    - (void)windowControllerDidLoadNib:(NSWindowController *) aController
    {
        [super windowControllerDidLoadNib:aController];
        // Add any code here that needs to be executed once the windowController has loaded the document's window.
    }
    
    - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError {
    	*outError = [NSError errorWithDomain:@"some error"
    								   code:666 
    							   userInfo:nil]; 
    	return YES;
    }
    
    - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError {
        return YES;
    }
    
    
     
  2. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    Apparently everything can be ignored, except NSError, even if you return only succes.
     

Share This Page