Need to Build an iOS App Around an API?

iOS Apps with REST APIs Cover

Making your first Swift app that uses a web service can be overwhelming. It seems like every time you try to figure it out you just add more things to learn to your list: REST, Alamofire, parsing JSON, OAuth, App Transport Security, setting headers, … But it doesn’t have to be confusing.

With iOS Apps with REST APIs skip the hundreds of pages that barely get into how to make a network call in iOS. No esoteric details about Core Anything or mathematical proofs of flatmap. Only the nitty gritty that you need to get real work done now: interfacing with your web services and displaying the results in your UI.

What Will I Be Able to Do?

After reading this book you’ll be able to:

  • Analyze a JSON response from a web service call and write Swift code to parse it into model objects.
  • Display those model objects in a table view so that when the user launches the app they have a nice list to scroll through.
  • Add authentication to use web service calls that require OAuth 2.0, a username/password, or a token.
  • Transition from the main table view to a detail view for each object, possibly making another web service call to get more info about the object.
  • Let users of your app add, modify and delete objects (as long as your web service supports it).
  • Hook in to more web service calls to extend you app, like adding user profiles or letting users submit comments or attach photos to objects.

To achieve those goals we’ll build out an app based on the GitHub API, focusing on gists. (If you’re not familiar with gists, they’re basically just text snippets, often code owned by a user on GitHub.) Your model objects might be bus routes, customers, chat messages, or whatever kind of object is core to your app.

We’ll start by figuring out how to make API calls in Swift then we’ll start building out our app one feature at a time:

  • Show a list of all public gists in a table view
  • Load more results when the user scrolls down
  • Let them pull to refresh to get the latest public gists
  • Load images from URLs into table view cells
  • Use OAuth 2.0 for authentication to get a list of a user’s private gists
  • Have a detail view for each gist showing the text
  • Allow users to add new gists, edit their own existing gists, and delete gists
  • Handle not having a network connection
I had to comment on how you progressed from simple NSURLSession calls to Alamofire serializers. I really like how you explained why you would choose to use one vs. the other and also how using some libraries can dramatically simplify the code and reduce boiler plate. I wish I didn’t have work to do so I could finish reading it all in one sitting.
Mark Johnson, Sr. Architect Apple Products at Proscape Technologies

What Will I Learn?

Right after you purchase iOS Apps with REST APIs, you’ll get all the information you need to build your first web service backed Swift app. Here’s what’s covered in this 234 page ebook:

  • 1. From JSON API to Swift App
  • 2. Our App’s Requirements
  • 3. Swift JSON Parsing & Networking Calls 101
  • 4. Why I Use Libraries Like Alamofire
  • 5. Hooking Up a REST API to a Table View
  • 6. Custom Headers
  • 7. Loading UITableViewCell Images from an API
  • 8. Pagination, a.k.a, Load More on Scroll
  • 9. Pull to Refresh
  • 10. Authentication
  • 11. Switching Lists
  • 12. Switching Between View Controllers & More JSON Parsing
  • 13. Adding More API Calls: Starring
  • 14. Deleting and Adding Gists
  • 15. Creating Gists and Clearing the Cache
  • 16. What if They’re Offline?
  • 17. What Next?
  • 18. Appendix: A Brief Introduction to CocoaPods

This book is for

  • Software developers getting started with iOS but experienced in other languages
  • Front-end devs looking to implement native UIs for iOS apps (no CSS, oh noes!)
  • Back-end devs tasked with getting the data into the user’s hands on iOS
  • Android, Windows Phone, Blackberry, Tizen, Symbian & Palm OS devs looking to expand their web service backed apps to iOS
  • Anyone whose boss is standing over their shoulder asking why the data isn’t showing up in the tableview yet

This book isn’t for:

  • People completely new to programming, you should have a decent grasp of at least one object-oriented programming language or have completed several intro to iOS tutorials
  • Designers, managers, UX pros, … It’s a programming book. All the monospace font inserts will probably drive you crazy.
  • Cross-platform developers dedicated to their tools (including HTML5 & Xamarin), this is all Swift & native UI, all the time
  • Programmers building apps with no webservice interaction
  • Game devs
I have pretty much used code and examples from every chapter. I have always been a Microsoft developer and only recently gotten into iPhone development. Your book is exactly what myself and my team needed to get started. Every example was relevant to what we needed for the application we are developing. Thank you for the fantastic job and I am looking forward to the update to the book and all future writings.
Igor Shpak, Director, North American Regions Applications, at Estee Lauder Companies
Start Building iOS Apps with REST APIs now for $29

(Buying for a group? Grab the discounted Team License from LeanPub.)

What version of Swift does it use?

The book was written in Swift 2.0, Alamofire 3.1, iOS 9, and Xcode 7. The book comes with free updates.

What formats does the book come in?

When you buy the book you’ll get it in PDF, EPUB, and MOBI formats.

Does my API need to be RESTful?

Not really, it’s just a convenient buzzword. All that I mean by “REST web service” or even most of the time that I say “web service” or “API” is that we can send an HTTP request and we get back some data in a format that’s easy to use in our app. Usually the response will be in JSON.

Web services are wonderful since they let you use existing systems in your own apps. They’re always a bit of a pain since every one has it’s own quirks but most of the integration is similar enough that we can generalize how to integrate them into our iOS apps.

In other words, if you want an argument about whether or not a web service is really RESTful you’re not going to find it here. We’ve got work that just needs to get done. Unless your API is SOAP based or something really esoteric the book will probably work for you.

How does the book work?

This book is mostly a series of tutorials in implementing a GitHub gists client app. Depending on how you learn best and how urgently you need to create your own app, there are 2 different approaches you might take:

  • Work through the tutorials as written, creating an app for GitHub Gists. You’ll understand how that app works and later be able to apply it to your own apps.
  • Read through the tutorials but implement them for your own app and API. Throughout the text I’ll point out where you’ll need to analyze your own requirements and API to help you figure out how to modify the example code to work with your API.

Are the code samples included?

All of the code samples in the book are freely available on GitHub and can be used in your own code under an MIT License. Each chapter has a tag allowing you to check out the code in progress up to the end of that chapter.

Does the book have DRM?

No, I don’t want you to have to fight to read the book on the device that you want. You can read the book on anything that will work with PDF, MOBI, or EPUB formats.

What if I’m not happy with the book?

If you’re not happy, I don’t want your money. If you don’t feel the book was worth the price or it’s not right for you or for any reason at all, then I’m happy to refund you. If it’s within 45 days after purchase then you can login to LeanPub and hit the button to get a no questions asked refund there. If it’s been longer than that, email me and I’ll refund you.

Did I Forget Something?

Just email me and I’ll answer ASAP.

Buy iOS Apps with REST APIs now for $29

Who Am I?

I’m Christina Moulton, an iOS app developer since 2010 who still randomly types retain]; once in a while. I develop custom iPhone & iPad apps at Teak Mobile Inc in Ontario, Canada. Every part of the process is fun: starting with initial concepts then designing the interface, writing code, and submitting apps to the App Store (well, not really the submission part, iTunesConnect is awful).

Right now I’m off sailing for a few years while writing about getting stuff done in Swift.

I love chatting about Swift. Email me or follow me on twitter.

Christina is the perfect example of the difference between hiring someone who’s just good at what they do and someone who’s great at what they do. In less than 30 days Christina produced an app still has some of our other developers mesmerized with how she produced such quality work in such a short period of time. Matt Scobel, Manager at Canon Innovation Lab
Christina is one of the brightest people I have worked with. She has an uncanny ability to work both at the system level and deep into the code, bringing multi-disciplinary knowledge and skills to bear. Dan Murray, President at DJM Consulting