Transparent Table View with a Background Image

A background image behind a table view can make your app look nicely customized without a ton of effort. There are a few pitfalls to make it look just right so let’s walk through how to add a background image to a UITableView. We’ll tweak the transparency so the table view cells look ok, stop extra empty cells from hiding the background image, and center & scale the image so it doesn’t get stretched.

Read on →

Parsing HTML and Downloading Files in Swift 2.0

While web APIs are getting more and more common some data at some point you’ll find yourself working with data that’s only available in HTML. I have a problem like this right now: NOAA makes all of their boating charts (depth and navigation maps) available online for free. But the index of files is just a huge HTML list or a funky web viewer. I want to download some charts to use offline but building an app to do that would require parsing the HTML list. The charts that I want are the Booklet format ones for the Atlantic coast.

HTML parsing support in iOS isn’t very good so handling tasks like this one can end up being quite a challenge. We’ll use the HTMLReader library to make it easier. Our app will have a table view listing the chart names and numbers. Tapping on a row will download the PDF chart. We’ll use Alamofire to download the PDF files and save them locally. And we’ll include an “Open In” function since the default PDF apps on iOS choke on PDFs with as much detail as these ones. Read on →

Saving Data to Show Offline

Sometimes we want to keep data between runs of our apps. NSUserDefaults is fine for a little bit of data. If there’s a lot of data then a full blown database makes sense, maybe Core Data, SQLite or Realm. But what if it’s a middling amount of data? Then use NSKeyedArchiver. It’s a lot simpler to set up than a database and can hold a lot more data than NSUserDefaults. If you don’t need fancy database features like querying then NSKeyedArchiver will save you a lot of coding time.

Today we’ll use NSKeyedArchiver to handle not having an internet connection in our Stock Quote Page View Controller demo app. We’ll do that by persisting the stock quotes each time we fetch them from the web service. Read on →

Why I Hate Ray Wenderlich’s Interview Questions just posted a list of Swift interview questions. After a quick scan though I couldn’t help but sigh. There are some interesting tidbits there that might be useful for evaluating some basic familiarity with the language. But what’s totally lacking is any context about how to use those questions to lead to a good hire. Maybe that’s not needed on a site about iOS tutorials but it’s not a discussion that I see happening anywhere else.

Don’t interview devs as if they’re writing a language. Maybe those abstruse details will help once a year. A developer who focuses on getting things done and caring about their user’s experiences will make a difference every day. Ask how they’d plan a project, what they think of a common library, what they’re proud of. Read on →

Adding an API-Backed UIPageViewController in Swift

Table views are the workhorse of iOS apps but sometimes being able to swipe through the data makes more sense. It’s particularly useful when there’s too much data to easily show in a tableview and the user just needs to pick something that’s good enough. If I were writing a Netflix app for myself I’d be tempted to use a page view: I’m usually just looking for something interesting enough to watch and I want to read the details about the movies instead of just seeing the titles and cover images.

Whatever your motivation for using a UIPageViewController, today we’re going to work through how to use one to display data from a REST API. We’ll be working with the Yahoo Finance API to get stock quotes again, like in Pull to Refresh Table View in Swift and NSNotifications in Swift. Here’s what our demo app will look like when it’s done:

Read on →

A Brief Introduction to CocoaPods

If you’re already familiar with CocoaPods, then you can probably skip this post. If you’re not, it’s worth taking a few minutes to learn about the lovely dependency manager commonly used for iOS libraries today.

CocoaPods is great for adding libraries to your iOS projects, in Objective-C and Swift. In fact, it’s easy to use Objective-C code in Swift projects. If you’re curious, check out Objective-C in Swift Project.

We’ll just cover the simple basics so that when a tutorial says something like add SwiftyJSON v2.2.0 to your project using CocoaPods you’ll know just what to do. Read on →

Why I Use Libraries Like Alamofire

There are a ton of jokes about that 2 hardest things in programming. Some say it’s naming things, estimating and off-by-one errors ;) Some say it’s estimating & getting paid. I think it’s nailing down your requirements (so you know what needs to get done) and keeping your code at a single level of abstraction. Read on →