mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-25 13:46:12 +08:00
Placing opening braces on a new line for methods to match Apple convention. Refs #614
Used uncrustify's "nl_fdef_brace = add" option to detect issues.
This commit is contained in:
@@ -39,44 +39,52 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
@synthesize performKeyValueValidation = _performKeyValueValidation;
|
||||
@synthesize ignoreUnknownKeyPaths = _ignoreUnknownKeyPaths;
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass {
|
||||
+ (id)mappingForClass:(Class)objectClass
|
||||
{
|
||||
RKObjectMapping* mapping = [self new];
|
||||
mapping.objectClass = objectClass;
|
||||
return [mapping autorelease];
|
||||
}
|
||||
|
||||
+ (id)mappingForClassWithName:(NSString *)objectClassName {
|
||||
+ (id)mappingForClassWithName:(NSString *)objectClassName
|
||||
{
|
||||
return [self mappingForClass:NSClassFromString(objectClassName)];
|
||||
}
|
||||
|
||||
+ (id)serializationMapping {
|
||||
+ (id)serializationMapping
|
||||
{
|
||||
return [self mappingForClass:[NSMutableDictionary class]];
|
||||
}
|
||||
|
||||
#if NS_BLOCKS_AVAILABLE
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass usingBlock:(void (^)(RKObjectMapping*))block {
|
||||
+ (id)mappingForClass:(Class)objectClass usingBlock:(void (^)(RKObjectMapping*))block
|
||||
{
|
||||
RKObjectMapping* mapping = [self mappingForClass:objectClass];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
+ (id)serializationMappingUsingBlock:(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 {
|
||||
+ (id)mappingForClass:(Class)objectClass withBlock:(void (^)(RKObjectMapping*))block
|
||||
{
|
||||
return [self mappingForClass:objectClass usingBlock:block];
|
||||
}
|
||||
|
||||
+ (id)mappingForClass:(Class)objectClass block:(void (^)(RKObjectMapping*))block {
|
||||
+ (id)mappingForClass:(Class)objectClass block:(void (^)(RKObjectMapping*))block
|
||||
{
|
||||
return [self mappingForClass:objectClass usingBlock:block];
|
||||
}
|
||||
|
||||
+ (id)serializationMappingWithBlock:(void (^)(RKObjectMapping*))block {
|
||||
+ (id)serializationMappingWithBlock:(void (^)(RKObjectMapping*))block
|
||||
{
|
||||
RKObjectMapping* mapping = [self serializationMapping];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
@@ -84,7 +92,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
|
||||
#endif // NS_BLOCKS_AVAILABLE
|
||||
|
||||
- (id)init {
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_mappings = [NSMutableArray new];
|
||||
@@ -98,7 +107,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
RKObjectMapping *copy = [[[self class] allocWithZone:zone] init];
|
||||
copy.objectClass = self.objectClass;
|
||||
copy.rootKeyPath = self.rootKeyPath;
|
||||
@@ -116,7 +126,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
- (void)dealloc
|
||||
{
|
||||
[_rootKeyPath release];
|
||||
[_mappings release];
|
||||
[_dateFormatters release];
|
||||
@@ -124,19 +135,23 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *)objectClassName {
|
||||
- (NSString *)objectClassName
|
||||
{
|
||||
return NSStringFromClass(self.objectClass);
|
||||
}
|
||||
|
||||
- (void)setObjectClassName:(NSString *)objectClassName {
|
||||
- (void)setObjectClassName:(NSString *)objectClassName
|
||||
{
|
||||
self.objectClass = NSClassFromString(objectClassName);
|
||||
}
|
||||
|
||||
- (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]]) {
|
||||
@@ -147,7 +162,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return mappings;
|
||||
}
|
||||
|
||||
- (NSArray *)relationshipMappings {
|
||||
- (NSArray *)relationshipMappings
|
||||
{
|
||||
NSMutableArray* mappings = [NSMutableArray array];
|
||||
for (RKObjectAttributeMapping* mapping in self.mappings) {
|
||||
if ([mapping isMemberOfClass:[RKObjectRelationshipMapping class]]) {
|
||||
@@ -158,24 +174,29 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return mappings;
|
||||
}
|
||||
|
||||
- (void)addAttributeMapping:(RKObjectAttributeMapping*)mapping {
|
||||
- (void)addAttributeMapping:(RKObjectAttributeMapping*)mapping
|
||||
{
|
||||
NSAssert1([[self mappedKeyPaths] containsObject:mapping.destinationKeyPath] == NO, @"Unable to add mapping for keyPath %@, one already exists...", mapping.destinationKeyPath);
|
||||
[_mappings addObject:mapping];
|
||||
}
|
||||
|
||||
- (void)addRelationshipMapping:(RKObjectRelationshipMapping*)mapping {
|
||||
- (void)addRelationshipMapping:(RKObjectRelationshipMapping*)mapping
|
||||
{
|
||||
[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 {
|
||||
- (id)mappingForSourceKeyPath:(NSString *)sourceKeyPath
|
||||
{
|
||||
for (RKObjectAttributeMapping* mapping in _mappings) {
|
||||
if ([mapping.sourceKeyPath isEqualToString:sourceKeyPath]) {
|
||||
return mapping;
|
||||
@@ -185,7 +206,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)mappingForDestinationKeyPath:(NSString *)destinationKeyPath {
|
||||
- (id)mappingForDestinationKeyPath:(NSString *)destinationKeyPath
|
||||
{
|
||||
for (RKObjectAttributeMapping* mapping in _mappings) {
|
||||
if ([mapping.destinationKeyPath isEqualToString:destinationKeyPath]) {
|
||||
return mapping;
|
||||
@@ -195,13 +217,15 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)mapAttributesCollection:(id<NSFastEnumeration>)attributes {
|
||||
- (void)mapAttributesCollection:(id<NSFastEnumeration>)attributes
|
||||
{
|
||||
for (NSString* attributeKeyPath in attributes) {
|
||||
[self addAttributeMapping:[RKObjectAttributeMapping mappingFromKeyPath:attributeKeyPath toKeyPath:attributeKeyPath]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mapAttributes:(NSString*)attributeKeyPath, ... {
|
||||
- (void)mapAttributes:(NSString*)attributeKeyPath, ...
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, attributeKeyPath);
|
||||
NSMutableSet* attributeKeyPaths = [NSMutableSet set];
|
||||
@@ -215,49 +239,60 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[self mapAttributesCollection:attributeKeyPaths];
|
||||
}
|
||||
|
||||
- (void)mapAttributesFromSet:(NSSet *)set {
|
||||
- (void)mapAttributesFromSet:(NSSet *)set
|
||||
{
|
||||
[self mapAttributesCollection:set];
|
||||
}
|
||||
|
||||
- (void)mapAttributesFromArray:(NSArray *)array {
|
||||
- (void)mapAttributesFromArray:(NSArray *)array
|
||||
{
|
||||
[self mapAttributesCollection:[NSSet setWithArray:array]];
|
||||
}
|
||||
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping serialize:(BOOL)serialize {
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping serialize:(BOOL)serialize
|
||||
{
|
||||
RKObjectRelationshipMapping* mapping = [RKObjectRelationshipMapping mappingFromKeyPath:relationshipKeyPath toKeyPath:keyPath withMapping:objectOrDynamicMapping reversible:serialize];
|
||||
[self addRelationshipMapping:mapping];
|
||||
}
|
||||
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
|
||||
{
|
||||
[self mapKeyPath:relationshipKeyPath toRelationship:keyPath withMapping:objectOrDynamicMapping serialize:YES];
|
||||
}
|
||||
|
||||
- (void)mapRelationship:(NSString*)relationshipKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
- (void)mapRelationship:(NSString*)relationshipKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
|
||||
{
|
||||
[self mapKeyPath:relationshipKeyPath toRelationship:relationshipKeyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
- (void)mapKeyPath:(NSString*)sourceKeyPath toAttribute:(NSString*)destinationKeyPath {
|
||||
- (void)mapKeyPath:(NSString*)sourceKeyPath toAttribute:(NSString*)destinationKeyPath
|
||||
{
|
||||
RKObjectAttributeMapping* mapping = [RKObjectAttributeMapping mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath];
|
||||
[self addAttributeMapping:mapping];
|
||||
}
|
||||
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
|
||||
{
|
||||
[self mapRelationship:keyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
|
||||
{
|
||||
[self mapRelationship:keyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
- (void)removeAllMappings {
|
||||
- (void)removeAllMappings
|
||||
{
|
||||
[_mappings removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)removeMapping:(RKObjectAttributeMapping*)attributeOrRelationshipMapping {
|
||||
- (void)removeMapping:(RKObjectAttributeMapping*)attributeOrRelationshipMapping
|
||||
{
|
||||
[_mappings removeObject:attributeOrRelationshipMapping];
|
||||
}
|
||||
|
||||
- (void)removeMappingForKeyPath:(NSString*)keyPath {
|
||||
- (void)removeMappingForKeyPath:(NSString*)keyPath
|
||||
{
|
||||
RKObjectAttributeMapping* mapping = [self mappingForKeyPath:keyPath];
|
||||
[self removeMapping:mapping];
|
||||
}
|
||||
@@ -265,7 +300,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
#ifndef MAX_INVERSE_MAPPING_RECURSION_DEPTH
|
||||
#define MAX_INVERSE_MAPPING_RECURSION_DEPTH (100)
|
||||
#endif
|
||||
- (RKObjectMapping*)inverseMappingAtDepth:(NSInteger)depth {
|
||||
- (RKObjectMapping*)inverseMappingAtDepth:(NSInteger)depth
|
||||
{
|
||||
NSAssert(depth < MAX_INVERSE_MAPPING_RECURSION_DEPTH, @"Exceeded max recursion level in inverseMapping. This is likely due to a loop in the serialization graph. To break this loop, specify one-way relationships by setting serialize to NO in mapKeyPath:toRelationship:withObjectMapping:serialize:");
|
||||
RKObjectMapping* inverseMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
for (RKObjectAttributeMapping* attributeMapping in self.attributeMappings) {
|
||||
@@ -286,11 +322,13 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return inverseMapping;
|
||||
}
|
||||
|
||||
- (RKObjectMapping*)inverseMapping {
|
||||
- (RKObjectMapping*)inverseMapping
|
||||
{
|
||||
return [self inverseMappingAtDepth:0];
|
||||
}
|
||||
|
||||
- (void)mapKeyPathsToAttributes:(NSString*)firstKeyPath, ... {
|
||||
- (void)mapKeyPathsToAttributes:(NSString*)firstKeyPath, ...
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, firstKeyPath);
|
||||
for (NSString* keyPath = firstKeyPath; keyPath != nil; keyPath = va_arg(args, NSString*)) {
|
||||
@@ -302,15 +340,18 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString*)attributeName {
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString*)attributeName
|
||||
{
|
||||
[self mapKeyPath:RKObjectMappingNestingAttributeKeyName toAttribute:attributeName];
|
||||
}
|
||||
|
||||
- (RKObjectAttributeMapping *)attributeMappingForKeyOfNestedDictionary {
|
||||
- (RKObjectAttributeMapping *)attributeMappingForKeyOfNestedDictionary
|
||||
{
|
||||
return [self mappingForKeyPath:RKObjectMappingNestingAttributeKeyName];
|
||||
}
|
||||
|
||||
- (RKObjectAttributeMapping*)mappingForAttribute:(NSString*)attributeKey {
|
||||
- (RKObjectAttributeMapping*)mappingForAttribute:(NSString*)attributeKey
|
||||
{
|
||||
for (RKObjectAttributeMapping* mapping in [self attributeMappings]) {
|
||||
if ([mapping.destinationKeyPath isEqualToString:attributeKey]) {
|
||||
return mapping;
|
||||
@@ -320,7 +361,8 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (RKObjectRelationshipMapping*)mappingForRelationship:(NSString*)relationshipKey {
|
||||
- (RKObjectRelationshipMapping*)mappingForRelationship:(NSString*)relationshipKey
|
||||
{
|
||||
for (RKObjectRelationshipMapping* mapping in [self relationshipMappings]) {
|
||||
if ([mapping.destinationKeyPath isEqualToString:relationshipKey]) {
|
||||
return mapping;
|
||||
@@ -330,25 +372,30 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)defaultValueForMissingAttribute:(NSString*)attributeName {
|
||||
- (id)defaultValueForMissingAttribute:(NSString*)attributeName
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)mappableObjectForData:(id)mappableData {
|
||||
- (id)mappableObjectForData:(id)mappableData
|
||||
{
|
||||
return [[self.objectClass new] autorelease];
|
||||
}
|
||||
|
||||
- (Class)classForProperty:(NSString*)propertyName {
|
||||
- (Class)classForProperty:(NSString*)propertyName
|
||||
{
|
||||
return [[RKObjectPropertyInspector sharedInspector] typeForProperty:propertyName ofClass:self.objectClass];
|
||||
}
|
||||
|
||||
#pragma mark - Date and Time
|
||||
|
||||
- (NSFormatter *)preferredDateFormatter {
|
||||
- (NSFormatter *)preferredDateFormatter
|
||||
{
|
||||
return _preferredDateFormatter ? _preferredDateFormatter : [RKObjectMapping preferredDateFormatter];
|
||||
}
|
||||
|
||||
- (NSArray *)dateFormatters {
|
||||
- (NSArray *)dateFormatters
|
||||
{
|
||||
return _dateFormatters ? _dateFormatters : [RKObjectMapping defaultDateFormatters];
|
||||
}
|
||||
|
||||
@@ -361,7 +408,8 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
|
||||
@implementation RKObjectMapping (DateAndTimeFormatting)
|
||||
|
||||
+ (NSArray *)defaultDateFormatters {
|
||||
+ (NSArray *)defaultDateFormatters
|
||||
{
|
||||
if (!defaultDateFormatters) {
|
||||
defaultDateFormatters = [[NSMutableArray alloc] initWithCapacity:2];
|
||||
|
||||
@@ -377,7 +425,8 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
return defaultDateFormatters;
|
||||
}
|
||||
|
||||
+ (void)setDefaultDateFormatters:(NSArray *)dateFormatters {
|
||||
+ (void)setDefaultDateFormatters:(NSArray *)dateFormatters
|
||||
{
|
||||
[defaultDateFormatters release];
|
||||
defaultDateFormatters = nil;
|
||||
if (dateFormatters) {
|
||||
@@ -386,12 +435,14 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
}
|
||||
|
||||
|
||||
+ (void)addDefaultDateFormatter:(id)dateFormatter {
|
||||
+ (void)addDefaultDateFormatter:(id)dateFormatter
|
||||
{
|
||||
[self defaultDateFormatters];
|
||||
[defaultDateFormatters insertObject:dateFormatter atIndex:0];
|
||||
}
|
||||
|
||||
+ (void)addDefaultDateFormatterForString:(NSString *)dateFormatString inTimeZone:(NSTimeZone *)nilOrTimeZone {
|
||||
+ (void)addDefaultDateFormatterForString:(NSString *)dateFormatString inTimeZone:(NSTimeZone *)nilOrTimeZone
|
||||
{
|
||||
NSDateFormatter *dateFormatter = [NSDateFormatter new];
|
||||
dateFormatter.dateFormat = dateFormatString;
|
||||
dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
|
||||
@@ -406,7 +457,8 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
|
||||
}
|
||||
|
||||
+ (NSFormatter *)preferredDateFormatter {
|
||||
+ (NSFormatter *)preferredDateFormatter
|
||||
{
|
||||
if (!preferredDateFormatter) {
|
||||
// A date formatter that matches the output of [NSDate description]
|
||||
preferredDateFormatter = [NSDateFormatter new];
|
||||
@@ -418,7 +470,8 @@ static NSDateFormatter *preferredDateFormatter = nil;
|
||||
return preferredDateFormatter;
|
||||
}
|
||||
|
||||
+ (void)setPreferredDateFormatter:(NSDateFormatter *)dateFormatter {
|
||||
+ (void)setPreferredDateFormatter:(NSDateFormatter *)dateFormatter
|
||||
{
|
||||
[dateFormatter retain];
|
||||
[preferredDateFormatter release];
|
||||
preferredDateFormatter = dateFormatter;
|
||||
|
||||
Reference in New Issue
Block a user