mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-22 03:43:59 +08:00
Added support for mapping NSURL properties. Fixes #52
This commit is contained in:
@@ -386,6 +386,8 @@ static const NSString* kRKModelMapperRailsDateFormatString = @"MM/dd/yyyy";
|
||||
} else {
|
||||
propertyValue = [NSNumber numberWithDouble:[propertyValue doubleValue]];
|
||||
}
|
||||
} else if (class == [NSURL class] && [propertyValue isKindOfClass:[NSString class]]) {
|
||||
propertyValue = [NSURL URLWithString:propertyValue];
|
||||
} else {
|
||||
[NSException raise:@"NoElementValueConversionMethod" format:@"Don't know how to convert %@ (%@) to %@", propertyValue, [propertyValue class], class];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
NSDate* _dateTest;
|
||||
NSNumber* _numberTest;
|
||||
NSString* _stringTest;
|
||||
NSURL* _urlTest;
|
||||
RKMappableAssociation* _hasOne;
|
||||
NSSet* _hasMany;
|
||||
}
|
||||
@@ -21,6 +22,7 @@
|
||||
@property (nonatomic, retain) NSDate* dateTest;
|
||||
@property (nonatomic, retain) NSNumber* numberTest;
|
||||
@property (nonatomic, retain) NSString* stringTest;
|
||||
@property (nonatomic, retain) NSURL* urlTest;
|
||||
@property (nonatomic, retain) RKMappableAssociation* hasOne;
|
||||
@property (nonatomic, retain) NSSet* hasMany;
|
||||
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
|
||||
@implementation RKMappableObject
|
||||
|
||||
@synthesize dateTest = _dateTest, numberTest = _numberTest, stringTest = _stringTest,
|
||||
@synthesize dateTest = _dateTest, numberTest = _numberTest, stringTest = _stringTest, urlTest = _urlTest,
|
||||
hasOne = _hasOne, hasMany = _hasMany;
|
||||
|
||||
+ (NSDictionary*)elementToPropertyMappings {
|
||||
return [NSDictionary dictionaryWithKeysAndObjects:@"date_test", @"dateTest",
|
||||
@"number_test", @"numberTest",
|
||||
@"string_test", @"stringTest", nil];
|
||||
@"string_test", @"stringTest",
|
||||
@"url_test", @"urlTest", nil];
|
||||
}
|
||||
|
||||
+ (NSDictionary*)elementToRelationshipMappings {
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
[expectThat([result dateTest]) shouldNot:be(nil)];
|
||||
[expectThat([result numberTest]) should:be(2)];
|
||||
[expectThat([result stringTest]) should:be(@"SomeString")];
|
||||
[expectThat([result urlTest]) should:be([NSURL URLWithString:@"https://github.com/twotoasters/RestKit"])];
|
||||
|
||||
[expectThat([result hasOne]) shouldNot:be(nil)];
|
||||
[expectThat([[result hasOne] testString]) should:be(@"A String")];
|
||||
@@ -329,6 +330,7 @@
|
||||
@" \"date_test\":\"2009-08-17T19:24:40Z\","
|
||||
@" \"number_test\":2,"
|
||||
@" \"string_test\":\"SomeString\","
|
||||
@" \"url_test\":\"https://github.com/twotoasters/RestKit\","
|
||||
@" \"has_one\":{"
|
||||
@" \"test_string\":\"A String\""
|
||||
@" },"
|
||||
|
||||
Reference in New Issue
Block a user