Skip to content

A couple commits to make life easier and more performant :) #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

andrebraga
Copy link

Hi, still haven't got around reworking the NSCoding/NSCopying code, but here are the couple other niceties I've worked on.

One allows assigning numeric values to numeric properties (both NSNumber and primitives) that exist as strings on the dictionary. Also changed NSDateFormatter allocation to happen statically, but optimised to only instantiate those that are actually requested (big performance boost). Finally changed passing property_attributes_t by reference, which is a small performance boost but nice to have nonetheless since it was trivial.

The other one is a trio of handful macros that help writing key paths and mappings/custom transform, all validated and autocompleted by Xcode. 😸

andrebraga and others added 11 commits May 9, 2014 12:37
…reate and are likely to be reused with some frequency. Instantiate them lazily however.

• Check whether the destination property is primitive or NSNumber-derived, and attempt to parse JSON string values into NSNumbers if so.
• Also, pass property_attributes_t by reference instead of copying it.
…d transforms.

- OSRKeyPath is inspired by EXTKeyPathCoding (from libextobjc), however it does away with the leading '@' to avoid hidden calls to +[NSString stringWithUTF8String:], simplifies it to always take (instance, key.path) arguments, and expands it to take a (class) type instead of an existing instance, making it usable in class methods without resorting to clunky workarounds.

Here's an example:

+ (NSDictionary *)reflectionMapping
{
	return @{
		@"id"		: OSRKeyPath(AUser*, Id),
		@"photos"	: OSRTransform(OSRKeyPath(AUser*, pictures)),
		@"whatevs"	: OSRAdapt(OSRKeyPath(AUser*, whatever), AWhateverClass)
	};
}

- (void)reflectionTranformsValue:(id)value forKey:(NSString *)propertyName
{
	if ([propertyName isEqual:OSRKeyPath(self, pictures)]) {
		self.pictures = [APicture objectsFromDicts:value];
	}
}
• Address potential differences between external and internal names for uniquing properties
• Handle parsing of numbers that are transmitted as strings at the uniquing predicate
• Trust key-value coding when the instance is a NSManagedObject (enables value transforms)
• Disable the NSCoding default implementation on NSObject(OSReflectionKit) that break NSManagedObject subclasses that are unarchived from the persistent store for not using their designated initialisers. Since the NSCopying implementation was also troublesome for interfering with Core Foundation types (like CGPath on Core Animation APIs), I just disabled them both.
• Minor change for consistency between header and implementation.
…ing recently exposed as the key. Saves *a lot* of trips to Core Data-land.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant