Adapting Images for Size Classes

I was lazy with my last post on how to use auto layout for proportional spacing. I started with three images in a horizontal row that were 120x120 points in size. Unfortunately that is too large to fit on a skinny device like the iPhone 4S. Rather than getting side-tracked with making the images adaptive I just used smaller images. That makes it fit on the smaller devices but wastes a lot of screen space on a larger iPad. Read On →

Proportional Spacing with Auto Layout

Auto Layout is a challenging topic to master. Stack Views and layout anchors introduced in iOS 9 help but it can still be difficult to see how to create certain layouts. In this post I want to look at a common situation where you need to position views at fixed proportions along an axis. It may not be obvious but that can be easily done using center alignments with a multiplier. Read On →

Swift Named Parameters

The rules for naming parameters in Swift functions and methods have changed for the better over the last few releases but still seem to cause confusion. Here is my quick summary updated for Swift 2.1. External vs Local Names The key to understanding parameter names in Swift is to remember that parameter names can have both an external and a local name: Local parameter names are used in the body of the function/method External parameter names are used when calling the function/method. Read On →

Using nullable to annotate Objective-C code

If you have tried and tested Objective-C code you do not need to rewrite it to use it in a Swift project. Unfortunately unless you take some extra steps the resulting Swift interface will treat all Objective-C references as implicitly unwrapped optionals. All those “!” symbols make for some ugly and unsafe Swift code. Fortunately there is a quick fix if you annotate your Objective-C header file with nullable and nonnull. Read On →

How to percent encode a URL String

When interacting with a web service it is common to have to percent encode reserved characters in the URL or form data. For example the percent encoding for the “&” character is “%26”. Figuring out which characters should be percent encoded in which part of a URL is not easy. The best sources seem to be RFC 3986 and the W3C HTML5 recommendation. So for fun and education I created a Swift String extension (and for comparison an Objective-C category) for both. Read On →
No time to watch WWDC videos?

Sign up to get my iOS posts direct to your inbox and I will send you a free PDF of my iOS Size Classes Cheat Sheet.

Unsubscribe at any time.