Accessorizer  generates keyed archiving code, copyWithZone: and other archiving methods.


Accessorizer gives you the option to generate constants for your literals.

.m

static NSString *KPC_TITLE = @"title";

static NSString *KPC_SONG = @"song";

static NSString *KPC_TRACK = @"track";

static NSString *KPC_TEMPO = @"tempo";



- (void) encodeWithCoder: (NSCoder *)coder

{

    [super encodeWithCoder: coder];

    [coder encodeObject: [self title] forKey: KPC_TITLE];

    [coder encodeObject: [self song] forKey: KPC_SONG];

    [coder encodeInt: [self track] forKey: KPC_TRACK];

    [coder encodeFloat: [self tempo] forKey: KPC_TEMPO];

}


- (id) initWithCoder: (NSCoder *)coder

{

    if (self = [super initWithCoder: coder]) {

        [self setTitle: [coder decodeObjectForKey: KPC_TITLE]];

        [self setSong: [coder decodeObjectForKey: KPC_SONG]];

        [self setTrack: [coder decodeIntForKey: KPC_TRACK]];

        [self setTempo: [coder decodeFloatForKey: KPC_TEMPO]];

    }

    return self;

}

static NSString ...

copyWithZone: ...

using

NSDictionary

#pragma mark -

#pragma mark archiving


#define KPC_TITLE @"title"

#define KPC_SONG @"song"

#define KPC_TRACK @"track"

#define KPC_TEMPO @"tempo"



- (void) encodeWithCoder: (NSCoder *)coder

{

    [super encodeWithCoder: coder];

    [coder encodeObject: [self title] forKey: KPC_TITLE];

    [coder encodeObject: [self song] forKey: KPC_SONG];

    [coder encodeInt: [self track] forKey: KPC_TRACK];

    [coder encodeFloat: [self tempo] forKey: KPC_TEMPO];

}


- (id) initWithCoder: (NSCoder *)coder

{

    if (self = [super initWithCoder: coder]) {

        [self setTitle: [coder decodeObjectForKey: KPC_TITLE]];

        [self setSong: [coder decodeObjectForKey: KPC_SONG]];

        [self setTrack: [coder decodeIntForKey: KPC_TRACK]];

        [self setTempo: [coder decodeFloatForKey: KPC_TEMPO]];

    }

    return self;

}


#define ...

- (id)copyWithZone:(NSZone *)zone

{

    id theCopy = nil;


    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self];


    if (data)

        theCopy = [[NSKeyedUnarchiver unarchiveObjectWithData:data] retain];


    return theCopy;

}

- (id)copyWithZone:(NSZone *)zone

{

    id theCopy = nil;


    NSDictionary *dictionary = [self dictionaryWithValuesForKeys:[self keyPaths]];


    if (dictionary) {

        theCopy = [[<class_name> allocWithZone:zone] init];

        [theCopy setValuesForKeysWithDictionary:dictionary];

    }


    return theCopy;

}

copyWithZone: ...

- (id)copyWithZone:(NSZone *)zone

{

    // use designated initializer

    id theCopy = [[<class_name> allocWithZone:zone] init];

 

    [theCopy setTitle: [self title]];

    [theCopy setSong: [self song]];

    [theCopy setTrack: [self track]];

    [theCopy setTempo: [self tempo]];


    return theCopy;

}

using setters

copyWithZone: ...

#pragma mark -

#pragma mark archiving


#define KPC_TITLE @"title"

#define KPC_SONG @"song"

#define KPC_TRACK @"track"

#define KPC_TEMPO @"tempo"



- (void) encodeWithCoder: (NSCoder *)coder

{

    [super encodeWithCoder: coder];

    [coder encodeObject: [self title] forKey: KPC_TITLE];

    [coder encodeObject: [self song] forKey: KPC_SONG];

    [coder encodeInt: [self track] forKey: KPC_TRACK];

    [coder encodeFloat: [self tempo] forKey: KPC_TEMPO];

}


- (id) initWithCoder: (NSCoder *)coder

{

    if (self = [super initWithCoder: coder]) {

        if ([coder containsValueForKey: KPC_TITLE])

            [self setTitle: [coder decodeObjectForKey: KPC_TITLE]];

        if ([coder containsValueForKey: KPC_SONG])

            [self setSong: [coder decodeObjectForKey: KPC_SONG]];

        if ([coder containsValueForKey: KPC_TRACK])

            [self setTrack: [coder decodeIntForKey: KPC_TRACK]];

        if ([coder containsValueForKey: KPC_TEMPO])

            [self setTempo: [coder decodeFloatForKey: KPC_TEMPO]];

    }

    return self;

}


containsValueForKey: ...

Keyed Archiving

What developers 
are saying ...testimonials.htmltestimonials.htmlshapeimage_6_link_0shapeimage_6_link_1
Videos & TutorialsaccessorizerVideos.htmlaccessorizerVideos.htmlshapeimage_8_link_0
Homeaccessorizer.htmlaccessorizer.htmlshapeimage_9_link_0
© 2002 - 2009 Kevin Callahanhttp://www.kevincallahan.orgshapeimage_10_link_0

KVO

Initialization MethodsinitMethods.htmlinitMethods.htmlshapeimage_11_link_0

Features

Indexed AccessorsindexedAccessors.htmlindexedAccessors.htmlshapeimage_12_link_0
BUYhttp://store.eSellerate.net/s.aspx?s=STR5524388698

only $15