• 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
Problem filing modified Sketch objects (Newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem filing modified Sketch objects (Newbie)


  • Subject: Problem filing modified Sketch objects (Newbie)
  • From: "J. Norvell" <email@hidden>
  • Date: Tue, 31 May 2005 23:53:35 -0700 (PDT)
  • Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys

Dear Coco-dev People,

I've modified Mike Ferris's Sketch example so that the SKTGraphic class has an
extra ivar, an NSMutableString.   When I save and open a Sketch document I can see
in the debugger that my instance variable has become "invalid" but I can't figure
out what I'm doing wrong.

I've tried a number of code "permutations" but nothing has worked:  I tried two
approaches to build the dictionary item for my new ivar, but neither one worked.
You can look at the code I've commented out to see what I tried.  I also created a
setTheCellID accessor (just for use during object creation) which only updated the
new ivar to see if the other parts of the setCellID accessor (undo and
notification) were causing the problem.  It didn't seem to matter which accessor I
used.

I've looked in Hillegass 2nd ed. and read Scott Stevenson's app. note "Saving
Application Data" but the Sketch filing paradigm differs from their approaches.
I've also reviewed Michael Beam's two Strings articles on oreillynet, Apple's
online Strings documentation, the Coco-dev archive, and Googled for clues.  I'm
stuck on this.

Comments, suggestions and code will be greatly appreciated!

Joel Norvell


Here are pertinent snippets of the Modified Sketch code.

    "..." indicates Sketch code shortened for brevity..
    "*** ADDED" indicates code I've added for the _cellID ivar.

// from SKTGraphic.h

@interface SKTGraphic : NSObject <NSCopying> {
    @private
    ...
    NSMutableString *_cellID; // *** ADDED
}

// from SKTGraphic.m

- (id)init {
    self = [super init];
    if (self) {
	...
        [self setTheCellID:[[NSMutableString alloc] initWithString:@"A01"]]; // ***
ADDED
    }
    return self;
}

- (void)dealloc {
    [_fillColor release];
    [_strokeColor release];
    [_cellID release]; // *** ADDED
    [super dealloc];
}

- (id)copyWithZone:(NSZone *)zone {
    id newObj = [[[self class] allocWithZone:zone] init];

    // Document is not "copied".  The new graphic will need to be inserted into a
document.
    ...
    [newObj setTheCellID:[self cellID]]; // *** ADDED

    return newObj;
}


- (void)setCellID:(NSMutableString *)theCellID {  // *** ADDED Accessor method
    if (_cellID != theCellID) {
        [[[self undoManager] prepareWithInvocationTarget:self]
setCellID:theCellID];
        _cellID = theCellID;
        [self didChange];
    }
}

- (void)setTheCellID:(NSMutableString *)theCellID {  // *** ADDED Accessor method
    if (_cellID != theCellID) {
        _cellID = theCellID;
    }
}

- (NSMutableString *)cellID {  // *** ADDED Accessor method
    return _cellID;
}

// for Persistence

NSString *SKTCellIDKey = @"CellID"; // *** ADDED

- (NSMutableDictionary *)propertyListRepresentation {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    NSString *className = NSStringFromClass([self class]);
    ...
//  [dict setObject:cellID forKey:SKTCellIDKey]; // *** ADDED
    [dict setObject:[NSArchiver archivedDataWithRootObject:[self cellID]]
forKey:SKTCellIDKey]; // *** ADDED
    return dict;
}

- (void)loadPropertyListRepresentation:(NSDictionary *)dict {
    id obj;
    ...
//  obj = [dict objectForKey:SKTCellIDKey]; // *** ADDED
//  if (obj) {                              // *** ADDED
//      [self setTheCellID:obj];            // *** ADDED
//  }                                       // *** ADDED

    obj = [dict objectForKey:SKTCellIDKey];                             // ***
ADDED
    if (obj) {                                                          // ***
ADDED
        [self setTheCellID:[NSUnarchiver unarchiveObjectWithData:obj]]; // ***
ADDED
    }                                                                   // ***
ADDED

    return;
}




__________________________________
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news and more. Check it out!
http://discover.yahoo.com/mobile.html
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Coredata schema question.
  • Previous by thread: NSFileHandle and FIFO files
  • Index(es):
    • Date
    • Thread