NSString coding errors
NSString coding errors
- Subject: NSString coding errors
- From: Adam Radestock <email@hidden>
- Date: Mon, 15 Jan 2007 22:53:31 +0000
Hi everyone,
I've just added an NSString object to one of my custom objects, which
conforms to the NSCoding Protocol, but am getting errors whenever I
try and encode the NSString object.
Below are my .h and .m files for the custom class, can anyone point
out the error in my code? I can't see the wood for the trees...
Thanks!
Adam Radestock
Glass Monkey Design Co
/* SCRPatch */
#import <Cocoa/Cocoa.h>
#define kBDPATCH_TYPE @"bdpatch"
#define kLINEUPPATCH_TYPE @"lineuppatch"
@interface SCRPatch : NSObject
{
NSMutableDictionary *properties;
NSMutableDictionary *qcPerameters;
NSString *patchTypeString;
}
- (void)encodeWithCoder:(NSCoder *)coder;
- (id)initWithCoder:(NSCoder *)coder;
- (id)copyWithZone:(NSZone *)zone;
- (NSMutableDictionary *)properties;
- (NSMutableDictionary *)qcPerameters;
- (NSString *)patchTypeString;
- (void)setProperties:(NSDictionary *)newProperties;
- (void)setQCPerameters:(NSDictionary *)newPerameters;
- (void)setPatchTypeString:(NSString *)newPatchTypeString;
- (id)valueForKey:(NSString *)key;
@end
#import "SCRPatch.h"
@implementation SCRPatch
- (id) init
{
if (self = [super init])
{
NSArray * keys = [NSArray arrayWithObjects:
@"patchName", @"patchPath", @"patchIcon", @"isPlaying", @"duration",
nil];
NSArray * values = [NSArray arrayWithObjects: [NSString
string], [NSString string], [NSNull null], [NSNull null], [NSNull
null], nil];
properties = [[NSMutableDictionary alloc] initWithObjects:
values forKeys: keys];
qcPerameters = [[NSMutableDictionary alloc] init];
patchTypeString = [NSString string];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
if ( [coder isKindOfClass:[NSKeyedArchiver class]] ) {
[coder encodeObject:properties forKey:@"SCRPatchProperties"];
[coder encodeObject:qcPerameters forKey:@"SCRPatchPerameters"];
[coder encodeObject:patchTypeString forKey:@"patchType"];
} else {
[NSException raise:NSInvalidArchiveOperationException
format:@"Only supports NSKeyedArchiver coders"];
}
return;
}
- (id)initWithCoder:(NSCoder *)coder
{
properties = [[coder decodeObjectForKey:@"SCRPatchProperties"]
retain];
qcPerameters = [[coder decodeObjectForKey:@"SCRPatchPerameters"]
retain];
patchTypeString = [[coder decodeObjectForKey:@"patchType"] retain];
return self;
}
- (id)copyWithZone:(NSZone *)zone {
return [self retain];
}
- (void) dealloc
{
[properties release];
[qcPerameters release];
[patchTypeString release];
[super dealloc];
}
- (NSMutableDictionary *)properties
{
return properties;
}
- (NSMutableDictionary *)qcPerameters
{
return qcPerameters;
}
- (NSString *)patchTypeString
{
return patchTypeString;
}
- (void) setProperties:(NSDictionary *)newProperties
{
if (properties != newProperties)
{
[properties autorelease];
properties = [[NSMutableDictionary alloc]
initWithDictionary:newProperties];
}
}
- (void) setQCPerameters:(NSDictionary *)newPerameters
{
if (qcPerameters != newPerameters)
{
[qcPerameters autorelease];
qcPerameters = [[NSMutableDictionary alloc]
initWithDictionary:newPerameters];
}
}
- (void)setPatchTypeString:(NSString *)newPatchTypeString
{
if (patchTypeString != newPatchTypeString)
{
[patchTypeString autorelease];
patchTypeString = [NSString stringWithString:newPatchTypeString];
NSLog(@"%@", patchTypeString);
}
}
- (id) valueForKey:(NSString *)key
{
if ([properties valueForKey:key] != nil) {
return [properties valueForKey:key];
}
else if ([qcPerameters valueForKey:key] != nil) {
return [qcPerameters valueForKey:key];
}
return nil;
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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