Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,687 changes: 1,168 additions & 519 deletions AFXMLDictionarySerializer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

69 changes: 35 additions & 34 deletions AFXMLDictionarySerializer/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,55 @@

#import "AppDelegate.h"
#import "AFXMLDictionaryResponseSerializer.h"
#import "XMLDictionarySettings.h"
#import <AFNetworking/AFHTTPRequestOperation.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *URL = [NSURL URLWithString:@"http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto&destination=Montreal&sensor=false"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFXMLDictionaryResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", responseObject);
} failure:nil];
[operation start];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSURL *URL = [NSURL URLWithString:@"http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto&destination=Montreal&sensor=false"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

AFXMLDictionaryResponseSerializer *dictionarySerializer = [AFXMLDictionaryResponseSerializer serializer];
XMLDictionarySettings *settings = [XMLDictionarySettings new];
settings.nodeNameMode = XMLDictionaryNodeNameModeAlways; // always add node __name
[dictionarySerializer configParser:settings];

operation.responseSerializer = dictionarySerializer;
[operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", responseObject);
} failure:nil];
[operation start];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
4 changes: 4 additions & 0 deletions Classes/AFXMLDictionaryResponseSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#import "AFURLResponseSerialization.h"

@class XMLDictionarySettings;

@interface AFXMLDictionaryResponseSerializer : AFHTTPResponseSerializer

- (void)configParser:(XMLDictionarySettings *)settingsObject;

@end
81 changes: 44 additions & 37 deletions Classes/AFXMLDictionaryResponseSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,76 @@

#import "AFXMLDictionaryResponseSerializer.h"
#import <XMLDictionary/XMLDictionary.h>
#import "XMLDictionarySettings.h"

@implementation AFXMLDictionaryResponseSerializer

+ (instancetype)serializer {
return [[self alloc] init];
return [[self alloc] init];
}

- (instancetype)init {
self = [super init];
if (!self) {
return nil;
}

self.acceptableContentTypes = [NSSet setWithObjects:@"application/xml", @"text/xml", nil];

return self;
self = [super init];
if (!self) {
return nil;
}

self.acceptableContentTypes = [NSSet setWithObjects:@"application/xml", @"text/xml", nil];

return self;
}

#pragma mark - Config parser

- (void)configParser:(XMLDictionarySettings *)settingsObject {
[XMLDictionaryParser sharedInstance].collapseTextNodes = settingsObject.collapseTextNodes;
[XMLDictionaryParser sharedInstance].stripEmptyNodes = settingsObject.stripEmptyNodes;
[XMLDictionaryParser sharedInstance].trimWhiteSpace = settingsObject.trimWhiteSpace;
[XMLDictionaryParser sharedInstance].alwaysUseArrays = settingsObject.alwaysUseArrays;
[XMLDictionaryParser sharedInstance].preserveComments = settingsObject.preserveComments;
[XMLDictionaryParser sharedInstance].attributesMode = settingsObject.attributesMode;
[XMLDictionaryParser sharedInstance].nodeNameMode = settingsObject.nodeNameMode;
}

#pragma mark - AFURLRequestSerialization

- (id)responseObjectForResponse:(NSURLResponse *)response
data:(NSData *)data
error:(NSError *__autoreleasing *)error
{
if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) {
if ([(NSError *)(*error) code] == NSURLErrorCannotDecodeContentData) {
return nil;
}
}

if ([data length] > 0)
{
return [NSDictionary dictionaryWithXMLData:data];
}
else
{
return nil;
}

return nil;
error:(NSError *__autoreleasing *)error {
if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) {
if ([(NSError *)(*error)code] == NSURLErrorCannotDecodeContentData) {
return nil;
}
}

if ([data length] > 0) {
return [NSDictionary dictionaryWithXMLData:data];
}

return nil;
}

#pragma mark - NSCoding

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (!self) {
return nil;
}
return self;
self = [super initWithCoder:aDecoder];
if (!self) {
return nil;
}

return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
[super encodeWithCoder:aCoder];
}

#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone {
AFXMLDictionaryResponseSerializer *serializer = [[[self class] allocWithZone:zone] init];
return serializer;
AFXMLDictionaryResponseSerializer *serializer = [[[self class] allocWithZone:zone] init];

return serializer;
}

@end
23 changes: 23 additions & 0 deletions Classes/XMLDictionarySettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// XMLParserSettings.h
// AFXMLDictionarySerializer
//
// Created by Илья Седов on 30.09.14.
// Copyright (c) 2014 Ideais Mobile. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <XMLDictionary.h>

@interface XMLDictionarySettings : NSObject

@property (nonatomic, assign) BOOL collapseTextNodes; // defaults to YES
@property (nonatomic, assign) BOOL stripEmptyNodes; // defaults to YES
@property (nonatomic, assign) BOOL trimWhiteSpace; // defaults to YES
@property (nonatomic, assign) BOOL alwaysUseArrays; // defaults to NO
@property (nonatomic, assign) BOOL preserveComments; // defaults to NO

@property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;
@property (nonatomic, assign) XMLDictionaryNodeNameMode nodeNameMode;

@end
25 changes: 25 additions & 0 deletions Classes/XMLDictionarySettings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// XMLParserSettings.m
// AFXMLDictionarySerializer
//
// Created by Илья Седов on 30.09.14.
// Copyright (c) 2014 Ideais Mobile. All rights reserved.
//

#import "XMLDictionarySettings.h"

@implementation XMLDictionarySettings

- (instancetype)init {
self = [super init];
if (self) {
_collapseTextNodes = YES;
_stripEmptyNodes = YES;
_trimWhiteSpace = YES;
_alwaysUseArrays = NO;
_preserveComments = NO;
}
return self;
}

@end
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"

pod 'AFNetworking', '>= 2.0'
pod 'AFNetworking', '>=2.4'
pod 'XMLDictionary'
23 changes: 12 additions & 11 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
PODS:
- AFNetworking (2.0.0):
- AFNetworking (2.4.1):
- AFNetworking/NSURLConnection
- AFNetworking/NSURLSession
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/UIKit
- AFNetworking/NSURLConnection (2.0.0):
- AFNetworking/NSURLConnection (2.4.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/NSURLSession (2.0.0):
- AFNetworking/NSURLSession (2.4.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (2.0.0)
- AFNetworking/Security (2.0.0)
- AFNetworking/Serialization (2.0.0)
- AFNetworking/UIKit (2.0.0):
- AFNetworking/Reachability (2.4.1)
- AFNetworking/Security (2.4.1)
- AFNetworking/Serialization (2.4.1)
- AFNetworking/UIKit (2.4.1):
- AFNetworking/NSURLConnection
- AFNetworking/NSURLSession
- XMLDictionary (1.3)

DEPENDENCIES:
- AFNetworking (>= 2.0)
- AFNetworking (>= 2.4)
- XMLDictionary

SPEC CHECKSUMS:
AFNetworking: 3fa983b1beaba69566a3374612511e2a6e3fe845
XMLDictionary: 27390d3517062694ccb307a7750250e1b687571d
AFNetworking: 0aabc6fae66d6e5d039eeb21c315843c7aae51ab
XMLDictionary: 40bf0ff87c5420ed20af746c663acd711826a6d0

COCOAPODS: 0.26.2
COCOAPODS: 0.34.1