mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-28 16:05:44 +08:00
Introduced the RKTableController component for iOS.
RKTableController provides a flexible, integrated system for driving iOS table views using the RestKit object mapping engine. Local domain objects can be mapped into table cells within a collection or presented for editing as part of a form. There are three flavors of table controllers available: * Static Tables: RKTableController can be used to render simple static tables that are composed of RKTableItems presented in RKTableSections. Table items can quickly be built and added to a table without a backing model or can have content object mapped into them for presentation. * Network Tables: RKTableController can also render a table with the results of a network load. The typical use case here is to have RestKit retrieve a JSON/XML payload from your remote system and then render the content into a table. * Core Data Tables: RKFetchedResultsTableController can efficiently drive a table view using objects pulled from a Core Data managed object context. Typical use-cases here are for the presentation of large collections that are pulled from a remote system, offering offline access, or speeding up a UI by using Core Data as a fast local cache. RKTableController supports a number of bells and whistles including integrated searching/filtering and pull to refresh.
This commit is contained in:
@@ -38,10 +38,11 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
@synthesize setNilForMissingRelationships = _setNilForMissingRelationships;
|
||||
@synthesize forceCollectionMapping = _forceCollectionMapping;
|
||||
@synthesize performKeyValueValidation = _performKeyValueValidation;
|
||||
@synthesize ignoreUnknownKeyPaths = _ignoreUnknownKeyPaths;
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass {
|
||||
RKObjectMapping* mapping = [self new];
|
||||
mapping.objectClass = objectClass;
|
||||
mapping.objectClass = objectClass;
|
||||
return [mapping autorelease];
|
||||
}
|
||||
|
||||
@@ -51,13 +52,28 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
|
||||
#if NS_BLOCKS_AVAILABLE
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass block:(void(^)(RKObjectMapping*))block {
|
||||
+ (id)mappingForClass:(Class)objectClass usingBlock:(void (^)(RKObjectMapping*))block {
|
||||
RKObjectMapping* mapping = [self mappingForClass:objectClass];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
+ (id)serializationMappingWithBlock:(void(^)(RKObjectMapping*))block {
|
||||
+ (id)serializationMappingUsingBlock:(void (^)(RKObjectMapping*))block {
|
||||
RKObjectMapping* mapping = [self serializationMapping];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
// Deprecated... Move to category or bottom...
|
||||
+ (id)mappingForClass:(Class)objectClass withBlock:(void (^)(RKObjectMapping*))block {
|
||||
return [self mappingForClass:objectClass usingBlock:block];
|
||||
}
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass block:(void (^)(RKObjectMapping*))block {
|
||||
return [self mappingForClass:objectClass usingBlock:block];
|
||||
}
|
||||
|
||||
+ (id)serializationMappingWithBlock:(void (^)(RKObjectMapping*))block {
|
||||
RKObjectMapping* mapping = [self serializationMapping];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
@@ -73,11 +89,30 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
self.setNilForMissingRelationships = NO;
|
||||
self.forceCollectionMapping = NO;
|
||||
self.performKeyValueValidation = YES;
|
||||
self.ignoreUnknownKeyPaths = NO;
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
RKObjectMapping *copy = [[[self class] allocWithZone:zone] init];
|
||||
copy.objectClass = self.objectClass;
|
||||
copy.rootKeyPath = self.rootKeyPath;
|
||||
copy.setDefaultValueForMissingAttributes = self.setDefaultValueForMissingAttributes;
|
||||
copy.setNilForMissingRelationships = self.setNilForMissingRelationships;
|
||||
copy.forceCollectionMapping = self.forceCollectionMapping;
|
||||
copy.performKeyValueValidation = self.performKeyValueValidation;
|
||||
copy.dateFormatters = self.dateFormatters;
|
||||
copy.preferredDateFormatter = self.preferredDateFormatter;
|
||||
|
||||
for (RKObjectAttributeMapping *mapping in self.mappings) {
|
||||
[copy addAttributeMapping:mapping];
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_rootKeyPath release];
|
||||
[_mappings release];
|
||||
@@ -86,29 +121,29 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSArray*)mappedKeyPaths {
|
||||
- (NSArray *)mappedKeyPaths {
|
||||
return [_mappings valueForKey:@"destinationKeyPath"];
|
||||
}
|
||||
|
||||
- (NSArray*)attributeMappings {
|
||||
- (NSArray *)attributeMappings {
|
||||
NSMutableArray* mappings = [NSMutableArray array];
|
||||
for (RKObjectAttributeMapping* mapping in self.mappings) {
|
||||
if ([mapping isMemberOfClass:[RKObjectAttributeMapping class]]) {
|
||||
[mappings addObject:mapping];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mappings;
|
||||
}
|
||||
|
||||
- (NSArray*)relationshipMappings {
|
||||
- (NSArray *)relationshipMappings {
|
||||
NSMutableArray* mappings = [NSMutableArray array];
|
||||
for (RKObjectAttributeMapping* mapping in self.mappings) {
|
||||
if ([mapping isMemberOfClass:[RKObjectRelationshipMapping class]]) {
|
||||
[mappings addObject:mapping];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@@ -121,13 +156,27 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[self addAttributeMapping:mapping];
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:@"<%@:%p objectClass=%@ keyPath mappings => %@>", NSStringFromClass([self class]), self, NSStringFromClass(self.objectClass), _mappings];
|
||||
}
|
||||
|
||||
- (id)mappingForKeyPath:(NSString*)keyPath {
|
||||
- (id)mappingForKeyPath:(NSString *)keyPath {
|
||||
return [self mappingForSourceKeyPath:keyPath];
|
||||
}
|
||||
|
||||
- (id)mappingForSourceKeyPath:(NSString *)sourceKeyPath {
|
||||
for (RKObjectAttributeMapping* mapping in _mappings) {
|
||||
if ([mapping.sourceKeyPath isEqualToString:keyPath]) {
|
||||
if ([mapping.sourceKeyPath isEqualToString:sourceKeyPath]) {
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)mappingForDestinationKeyPath:(NSString *)destinationKeyPath {
|
||||
for (RKObjectAttributeMapping* mapping in _mappings) {
|
||||
if ([mapping.destinationKeyPath isEqualToString:destinationKeyPath]) {
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
@@ -145,13 +194,13 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
va_list args;
|
||||
va_start(args, attributeKeyPath);
|
||||
NSMutableSet* attributeKeyPaths = [NSMutableSet set];
|
||||
|
||||
|
||||
for (NSString* keyPath = attributeKeyPath; keyPath != nil; keyPath = va_arg(args, NSString*)) {
|
||||
[attributeKeyPaths addObject:keyPath];
|
||||
}
|
||||
|
||||
|
||||
va_end(args);
|
||||
|
||||
|
||||
[self mapAttributesCollection:attributeKeyPaths];
|
||||
}
|
||||
|
||||
@@ -211,7 +260,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
for (RKObjectAttributeMapping* attributeMapping in self.attributeMappings) {
|
||||
[inverseMapping mapKeyPath:attributeMapping.destinationKeyPath toAttribute:attributeMapping.sourceKeyPath];
|
||||
}
|
||||
|
||||
|
||||
for (RKObjectRelationshipMapping* relationshipMapping in self.relationshipMappings) {
|
||||
if (relationshipMapping.reversible) {
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
@@ -222,7 +271,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[inverseMapping mapKeyPath:relationshipMapping.destinationKeyPath toRelationship:relationshipMapping.sourceKeyPath withMapping:[(RKObjectMapping*)mapping inverseMappingAtDepth:depth+1]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return inverseMapping;
|
||||
}
|
||||
|
||||
@@ -242,7 +291,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString*)attributeName {
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString*)attributeName {
|
||||
[self mapKeyPath:RKObjectMappingNestingAttributeKeyName toAttribute:attributeName];
|
||||
}
|
||||
|
||||
@@ -256,7 +305,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -266,7 +315,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -284,7 +333,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
|
||||
#pragma mark - Date and Time
|
||||
|
||||
- (NSDateFormatter *)preferredDateFormatter {
|
||||
- (NSFormatter *)preferredDateFormatter {
|
||||
return _preferredDateFormatter ? _preferredDateFormatter : [RKObjectMapping preferredDateFormatter];
|
||||
}
|
||||
|
||||
@@ -346,7 +395,7 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
|
||||
}
|
||||
|
||||
+ (NSDateFormatter *)preferredDateFormatter {
|
||||
+ (NSFormatter *)preferredDateFormatter {
|
||||
if (!preferredDateFormatter) {
|
||||
// A date formatter that matches the output of [NSDate description]
|
||||
preferredDateFormatter = [NSDateFormatter new];
|
||||
|
||||
Reference in New Issue
Block a user