Why I Hate Ray Wenderlich’s Interview Questions

RayWenderlich.com 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 →

Getting an OAuth 2.0 Token with Alamofire

OAuth 2.0 is super common for authentication these days, largely since it lets you login without giving your password to every app you use. If you’re not familiar with OAuth check out the great explanation on RayWenderlich.com. For example, if you wanted to let an iOS app have some access to your Twitter account, then the OAuth2 auth flow would be:

  1. The app sends you to Twitter to login
  2. You login to Twitter to authorize the app (possibly giving it specific limited permissions)
  3. Twitter sends you back to the app with a token for that app to use

The flow can be a little confusing (in fact, there’s an extra step that we’ll add later) but it means that the iOS app never knows your password. It also lets you revoke its permission later without changing your Twitter password.

When building any app build around an API with OAuth 2.0 authentication the first thing you need to do is setting up that login flow to get a token. So that’s what we’ll do today. We’ll set up a simple Swift app to access the GitHub API to get a list of our repositories on GitHub. Read on →

Objective-C in Swift Projects

While Swift is quickly gaining popularity there’s are still tons of great bits of code only available in Objective-C that you might want to use in your project. Today we’ll figure out how to use an Objective-C class in a Swift project. We’ll do it first by importing the files into the project manually, then we’ll do it using CocoaPods. Read on →

Changing API Call Parameters in One UITableView

We’ve set up a few different Swift tableviews that show results from a webservice:

Today we’ll improve on one of those projects to let the user choose different results to display in the table view. We’ll extend the Pull to Refresh Table View to have a segmented control so they can choose from a few different types of stocks to display, instead of just Apple, Google & Yahoo. Here’s what it’ll look like when we’re done:

Pull to Refresh Table View showing telecom stocks
Table View with Options
Read on →

App Extensions: Creating a Notification Center Widget

As of iOS 8 your app can add a section to the Notification Center that users see when they swipe down from the top of the screen. This view is called a Today extension or just a widget.

Today we’ll create a simple app with a today widget. It’ll just tell you the last time you ran the main app. Since extensions aren’t part of the app they’re associated with that’ll require:

  • a main app that saves the time it’s run
  • an extension app that displays it
  • and a data store that’s shared between the two apps
Read on →

Programmatic UITableView Scrolling

Scrolling to a certain point in a table view is a common requirement. For example, you might scroll to show new entries after loading new data or to show that a row has updated data. Since UITableView inherits from UIScrollView it’s easy to scroll programmatically.

In this demo we’ll set up a few different scrolling actions. To select where we want to scroll to we’ll use an Action Sheet, implementing as a UIAlertController with the .ActionSheet style. It’ll have a UIAlertAction for each of the scroll options. Read on →

NSNotifications in Swift

Today we'll build a cute little stock ticker that automatically updates every second. Here's what it'll look like when we're done:

Most of the app is the same as our pull to refresh project with a tableview that displays stock info from the Yahoo financial API. Originally we set it up to update using pull to refresh. Today we'll switch it to automatically update and use NSNotifications to make the data available to the tableview. Read on →