mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Major overhaul to the Core Data managed object identification and relationship connection support.
* Replaces primary key with `RKEntityIdentifier` * Add support for use of compound keys for object identification * Refactor `RKConnectionMapping` to `RKConnectionDescription` and add support for connecting with multiple attributes * Clarify naming of representation key methods to better match naming conventions * Add type transformation support for object identification * Greatly expand test coverage for object identification * Drop the `NSEntityDescription` category * Simplify the `RKManagedObjectCaching` protocol * Add compound key support to the Fetch Request and In Memory Cache implementations * Replace Kiwi with Specta for tests where contexts are helpful for organization * Rename `defaultValueForMissingAttribute` to `defaultValueForAttribute`
This commit is contained in:
53
Code/ObjectMapping/RKValueTransformers.m
Normal file
53
Code/ObjectMapping/RKValueTransformers.m
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// RKValueTransformers.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 11/26/12.
|
||||
// Copyright (c) 2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKValueTransformers.h"
|
||||
#import "RKMacros.h"
|
||||
|
||||
// Implementation lives in RKObjectMapping.m at the moment
|
||||
NSDate *RKDateFromStringWithFormatters(NSString *dateString, NSArray *formatters);
|
||||
|
||||
@implementation RKDateToStringValueTransformer
|
||||
|
||||
+ (Class)transformedValueClass
|
||||
{
|
||||
return [NSDate class];
|
||||
}
|
||||
|
||||
+ (BOOL)allowsReverseTransformation
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id)initWithDateToStringFormatter:(NSFormatter *)dateToStringFormatter stringToDateFormatters:(NSArray *)stringToDateFormatters
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
self.dateToStringFormatter = dateToStringFormatter;
|
||||
self.stringToDateFormatters = stringToDateFormatters;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)transformedValue:(id)value
|
||||
{
|
||||
NSAssert(self.stringToDateFormatters, @"Cannot transform an `NSDate` to an `NSString`: stringToDateFormatters is nil");
|
||||
RKAssertValueIsKindOfClass(value, [NSString class]);
|
||||
return RKDateFromStringWithFormatters(value, self.stringToDateFormatters);
|
||||
}
|
||||
|
||||
- (id)reverseTransformedValue:(id)value
|
||||
{
|
||||
NSAssert(self.dateToStringFormatter, @"Cannot transform an `NSDate` to an `NSString`: dateToStringFormatter is nil");
|
||||
RKAssertValueIsKindOfClass(value, [NSDate class]);
|
||||
@synchronized(self.dateToStringFormatter) {
|
||||
return [self.dateToStringFormatter stringForObjectValue:value];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user