• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Document-based Application Template
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Document-based Application Template


  • Subject: Re: Cocoa Document-based Application Template
  • From: Karolis Ramanauskas <email@hidden>
  • Date: Thu, 26 Feb 2009 23:36:30 -0600

You have to set up how you will save your files first, this is not core
data.

You will have to, for example, create an array that will hold the objects
that you will be archiving and unarchiving to. Then you will have to modify
the dataOfType and readFromData methods:

- (id)init {

    self = [super init];
    if (self) {

        objectsToArchive = [[NSMutableArray alloc] init];
        selection = [[NSMutableArray alloc] init];

    }

    return self;

}

- (void)dealloc {

    [objectsToArchive release];
    [selection release];

    [super dealloc];

}

- (void)addObject : (id)object {

    if(![objectsToArchive containsObject:object]) {

        [objectsToArchive addObject:object];

    }

}

- (void)removeObject : (id)object {

    [objectsToArchive removeObject:object];

}

- (void)setObjects : (NSMutableArray*)objects {

    [objects retain];
    [objectsToArchive release];
    objectsToArchive = objects;

}

- (NSArray*)objects {

    return objectsToArchive;

}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {

    if ( outError != NULL ) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:
unimpErr userInfo:NULL];
    }

    return [NSKeyedArchiver archivedDataWithRootObject:[self objects]];

}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError {

    if ( outError != NULL ) {
        *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:
unimpErr userInfo:NULL];
    }

    NSArray * arrayWithDataFromFile = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
    NSMutableArray * mutableArrayWithDataFromFile = [arrayWithDataFromFile
mutableCopy];

    [self setObjects: mutableArrayWithDataFromFile];

    [mutableArrayWithDataFromFile release];

    return YES;

}

On Thu, Feb 26, 2009 at 11:05 PM, Richard Somers <email@hidden
> wrote:

> An application built using the standard unmodified "Cocoa Document-based
> Application" template produces an error when saving. The error message is
> "The document "Untitled" could not be saved as "newname.????".
>
> This happens on my PPC and Intel machines.
>
> Does anyone else have this problem?
>
> Mac OS X 10.5.5
> Xcode 3.1.1
>
> Richard
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Cocoa Document-based Application Template
      • From: Richard Somers <email@hidden>
References: 
 >Cocoa Document-based Application Template (From: Richard Somers <email@hidden>)

  • Prev by Date: Re: Why doesn't this work on my device?
  • Next by Date: Re: Using NSTableView without Nib files
  • Previous by thread: Cocoa Document-based Application Template
  • Next by thread: Re: Cocoa Document-based Application Template
  • Index(es):
    • Date
    • Thread