Skip to content

A category on NSObject which makes it easy to archive a class's properties in one method call

Notifications You must be signed in to change notification settings

mattrajca/FastCoding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FastCoding

The FastCoding category on NSObject reduces the amount of code developers have to write to archive properties defined on their classes. By utilizing the convenience methods FastCoding provides while implementing initWithCoder: and encodeWithCoder:, repetitive code that looks like this:

- (id)initWithCoder:(NSCoder *)aDecoder {
	self = [super init];
	if (self) {
		self.name = [aDecoder decodeObjectForKey:@"name"];
		self.size = [aDecoder decodeSizeForKey:@"size"];
		self.color = [aDecoder decodeObjectForKey:@"color"];
	}
	return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
	[aCoder encodeObject:name forKey:@"name"];
	[aCoder encodeSize:size forKey:@"size"];
	[aCoder encodeObject:color forKey:@"color"];
}

... can quickly be turned into this:

- (id)initWithCoder:(NSCoder *)aDecoder {
	self = [super init];
	if (self) {
		[self decodePropertiesWithCoder:aDecoder];
	}
	return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
	[self encodePropertiesWithCoder:aCoder];
}

To use FastCoding on projects targeting Mac OS X 10.7 or later, simply copy the NSObject+FastCoding.[hm] files over to your Xcode project. Earlier releases of Mac OS X are currently unsupported. The FastCoding Xcode project includes unit tests which can be run to discern regressions. Additionally, all of FastCoding's functionality takes advantage of Objective-C's dynamic runtime.

About

A category on NSObject which makes it easy to archive a class's properties in one method call

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published