Alamofire 5 Tutorial for iOS: Getting Started | raywenderlich.com

In this Alamofire tutorial, you’ll build an iOS companion app to perform networking tasks, send request parameters, decode/encode responses and more.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6587213-alamofire-5-tutorial-for-ios-getting-started

I notice a complete lack of error handling in this code. Do you think you could revise it, or offer a separate article on how to deal with error conditions, such as lack of Internet connection, malformed data, and so on?

@iain.delaney Thanks very much for your question!

You raise a good point, but do keep in mind that this is an introductory tutorial on using Alamofire for implementing networking functionality in iOS. For this reason, such a tutorial would focus on getting the user up and running in working with this popular, third party library as quickly as possible. By doing so, the user is introduced to the fundamentals of using this API very quickly to ensure they understand the core concepts of networking using Alamofire with minimal effort.

You will also notice that in this tutorial, other concepts are also introduced as well, such as JSON parsing using the Decodable protocol. Because our tutorials need to be of a certain length in order to avoid overwhelming the reader, certain topics unfortunately need to be edited out. If other topics like error handling were also included, then this tutorial would be even longer.

Because this tutorial is entitled, “Getting Started”, it would be fair to say that error handling will be discussed in a follow up tutorial in the near future. :slight_smile:

I hope this helps!

All the best.

It appears that the endpoints in the code example are not working as expected, returning 404 errors.

Hi Brian! Thanks for letting me know. I apologize for the inconvenience. I have been speaking with the API owner and it looks like the API is down for good. I am currently investigating possible fixes and will post an update here once the problem is resolved.

The issue with the article has been resolved. It has been updated to use a forked version of the API at swapi.dev. The project has also been updated so please download the Download Materials again.

Hello, I’m still a beginner in iOS development and I’m trying to build an app that uses Alamofire like in this tutorial, but I have a problem. The summary of Alamofire in my project says “Reference to Session.default for quick bootstrapping and examples” and AF is being declared as type Session while the summary for Alamofire in this project says “Global namespace containing API for the default Session instance.” while AF is an enumeration. Do you mind suggesting what I could do so that Alamofire in my project would become an enumeration as well? Thank you!

The version of Alamofire in this project is 5.0.0-rc3, but the Alamofire Software Foundation has been busy releasing updates and are currently up to version 5.2.1. One of the changes was to remove the AF enum and convert it to a global property. This is the difference that you are seeing between this project and your project. When AF was an enum it was just a wrapper for Session.default. If you are not familiar with wrappers they are just a way of hiding the complexity of another object. But here is the great thing: the functionality between the enum AF and the global property AF are identical! You should not notice any difference in your code. In fact, I re-built the StarWarsOpedia project using Alamofire 5.2.1 which uses the AF global property and it works exactly the same. All of the AF.request calls you learned about in the article should work exactly the same with version 5.2.1. :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!