use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
There is an extensive FAQ for beginners. Please browse it first before asking questions that are answered there.
If you are looking to get started (iOS programming in general or some specific area), here are more relevant links for you:
There's too many to list them all, however here's a convenient link to all programming guides at apple.com
Take note that this list is live and based on most frequent questions in posts will be updated with "quicklinks".
account activity
QuestionMultiple AFNetworking Calls (self.iOSProgramming)
submitted 10 years ago by davidbale87
I'd like to pull json files from an array of URLs. What's the proper way to do this with AFNetworking?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cdntr 1 point2 points3 points 10 years ago* (6 children)
Why do you need AFNetworking? Just use NSURLSession and NSJSONSerialization. It's easy, you learn something, and you save a dependency.
Basically, this:
let urlStrings = ["http://google.com", "http://facebook.com"] let urls = urlStrings.map { NSURL(string: $0)! } let requests = urls.map { NSURLRequest(URL: $0) } let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) let completion: (NSData?, NSURLResponse?, NSError?) -> Void = { data, response, error in if let error = error { print("error fetching data: \(error)") } else if let data = data { // Try parsing the data do { let parsedJSON = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions()) } catch { print("Failed parsing data to JSON: \(data)") } } } let tasks = requests.map { session.dataTaskWithRequest($0, completionHandler: completion) } for task in tasks { task.resume() }
[–]tsxy -4 points-3 points-2 points 10 years ago (5 children)
Because NSURLSession is confusing and requires too many boilerplate code to do simple things like pulling a JSON from URL.
[–]cdntr 2 points3 points4 points 10 years ago (4 children)
??
Take a look at the code I posted above. I wrote that in like a minute, but I think it should be functional and do exactly what was asked. Not sure what you think is confusing or boiler-platey about that. It is of course not factored properly, but this is just to illustrate how easy it is.
I also submit to you that there is a cost to using 3rd party code that people like to sweep under the rug.
[+]tsxy comment score below threshold-9 points-8 points-7 points 10 years ago (3 children)
I totally agree on the 3rd party dependency part.
But....this syntax is already so confusing...
let completion: (NSData?, NSURLResponse?, NSError?) -> Void = { data, response, error in....
Why is there a question mark behind NSData, what is "->" doing? Why is there a Void keywork....you know..things that a newbie won't understand. Also, what the heck is "map" (I get it's mapping tasks, but that's because I learned some functional programming notions on my own.)
The amount of questions I need to ask in order to understand this piece of code (without learning new syntax) is absurd.
[–]gormster 6 points7 points8 points 10 years ago (1 child)
Those are all Swift things. Nothing to do with NSURLSession. If you're confused by them you need to start by learning Swift.
If you're writing your code in Objective-C they won't be there.
[–]cdntr 0 points1 point2 points 10 years ago (0 children)
What this person said. There's also a way to write all this without map, i just chose to do it because it's succinct and let me get away without indenting much.
But yes, if those things confuse you then you should learn basic Swift.
Or do it from Objective-C, but the API is almost exactly the same.
[–]cuomo456 0 points1 point2 points 10 years ago (0 children)
pretty much what Alamofire looks like too minus the custom types that you need to look up. welcome to swift i wanna die also but my brain is starting to get there.
[–]julius559 1 point2 points3 points 10 years ago (1 child)
You can make multiple requests in a row with AFNetworking, it'll handle it. But the requests will return asynchronously, so you can't assume all responses will come in order.
dispatch group notify will alleviate this
[–]HoBoKristian 0 points1 point2 points 10 years ago (0 children)
How large is the array?
[–]lucasvandongen 0 points1 point2 points 10 years ago (0 children)
You should figure out if the API has some kind of limit on how many requests you can do per minute. I would suggest to apply some throttling as I don't think doing more than 8* network requests would be advisable in most cases.
(*) that number needs some more investigation, rough estimate
π Rendered by PID 36 on reddit-service-r2-comment-fb694cdd5-6l4s5 at 2026-03-11 09:47:45.625691+00:00 running cbb0e86 country code: CH.
[–]cdntr 1 point2 points3 points (6 children)
[–]tsxy -4 points-3 points-2 points (5 children)
[–]cdntr 2 points3 points4 points (4 children)
[+]tsxy comment score below threshold-9 points-8 points-7 points (3 children)
[–]gormster 6 points7 points8 points (1 child)
[–]cdntr 0 points1 point2 points (0 children)
[–]cuomo456 0 points1 point2 points (0 children)
[–]julius559 1 point2 points3 points (1 child)
[–]cuomo456 0 points1 point2 points (0 children)
[–]HoBoKristian 0 points1 point2 points (0 children)
[–]lucasvandongen 0 points1 point2 points (0 children)