13

I got an news app which fetches news online in XML format in stores it locally in the sqlite dbase.. which is perfect case for restkit.

However, I would like to also fetch xml data manually sometimes (ie and not want to store it in the dbase).. in other words i would like to request it directly with AFNetworking. I like how in AFNetworking 2.0 it does the parsing of xml automatically, and so I want to use that feature.

However, Restkit 2.0 is linked to AFNetworking 1.3.. and so If I add this to my podfile:

pod 'RestKit', '~> 0.21.0'
pod "AFNetworking", "~> 2.0"

and run a pod install I get the following error:

[!] Unable to satisfy the following requirements:
- `AFNetworking (~> 1.3.0)` required by `RestKit/Network (0.21.0)`- `AFNetworking (~> 2.0)` required by `Podfile`

is there anyway around this?

abbood
  • 23,101
  • 16
  • 132
  • 246

3 Answers3

3

In version 1.3.0 you have access to AFXMLRequestOperation which should fulfil the same goal.

It would be a lot of work to update RestKit to use version 2.0, or to rename so that you could use both versions...

Wain
  • 118,658
  • 15
  • 128
  • 151
  • yes it achieves the same goal.. but with a lot more work (ie it returns an instance of `NSXMLParser`, so I'll still have to implement the `NSXMLParserDelegate` methods) – abbood Feb 01 '14 at 10:51
  • Then I'd look at using a normal operation and https://github.com/nicklockwood/XMLDictionary – Wain Feb 01 '14 at 11:45
  • interesting library.. however an `XMLDictionaryParser` can only be instantiated by either data, string, or path. How do I make it work with AFNetworking? If i'm going to have to jump back and basically use basic NSUrlrequest stuff to just load the data off a remote server i think it would defeat the purpose of trying to simplify this whole thing. – abbood Feb 01 '14 at 13:14
  • oh ok.. found it [here](https://github.com/nicklockwood/XMLDictionary/pull/11).. it wasn't in the original library but in a fork of it. Thanks! Will update my question with the final code if you don't mind (once i get it running that is) – abbood Feb 01 '14 at 13:16
  • What do you mean update RestKit to use version 2.0? Does RestKit support AFNetworking 2.0?? – Plot Mar 03 '14 at 12:19
  • @Plot, not yet, support for AFN 2 is work-in-progress for RestKit (check the branches on github). – Wain Mar 03 '14 at 12:21
1

A quick and dirty solution could be to just rename the files of afnetworking to af1networking and all the classes/interfaces/constants to AF1xxxx. If we only had namespaces in Objective-C or the AFNetworking guys would have prefixed the new version with AF2...

I think what i describe could be done with a project search and replace in hours.

An Alternative would be to use MKNetworkKit for the networking - it is similiar to afnetworking/afnetworking2 but then you end up having 2 different network libraries and AFNetworking seems to have more effort put into.

0

Using a forked version of XMLDictionary, I basically achieved what I wanted to achieve by asking the above question by doing the following:

NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFXMLRequestOperation *operation =
[AFXMLRequestOperation XMLParserRequestOperationWithRequest:request
 success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {

    NSDictionary *dict = [NSDictionary dictionaryWithXMLParser:XMLParser];
    // do stuff with dict        

 failure:failure:^(NSURLRequest *request, NSHTTPURLResponse *response, 
                   NSError *error, NSXMLParser *XMLParser){

    NSLog(@"somethign weng wrong in fetching news data: %@", 
                 [error localizedDescription]);
}];

[operation start];

Credit goes to Wain in his answer's comments :)

Community
  • 1
  • 1
abbood
  • 23,101
  • 16
  • 132
  • 246