Fri, Aug 29
Creating a Custom Control in Swift

Mikael Konutgan of the Ray Wenderlich team recently wrote about creating a custom control in Swift. The completed control will look as follows:

Swift custom control.

If you are looking to build a control that has a basic target-action pattern, read on.

UIControl implements the target-action pattern, which is a mechanism for notifying subscribers of changes. UIControl also has a few properties that relate to control state. You’ll be using the target-action pattern in this custom control, so UIControl will serve as a great starting point.

Apple Case Study on Optionals in Swift

Apple Swift Blog:

This post explores how optionals help preserve strong type safety within Swift. We’re going to create a Swift version of an Objective-C API.

There is coverage of several concepts: returning an array of optionals from a method, using the map method on an array and a few notes about return values of Optional(nil).

Thu, Aug 28
Converting Values to Enumerations in Swift

From the #swift-lang IRC channel: “Is there any way to go backwards in an enum? I want to look up an enum based on a value.”

Erica Sadun:

The RawRepresentable protocol consists of two underlying functions: toRaw() and fromRaw(). These enable you to transform enumerations to and from underlying data states.

Swift’s Answer to #pragma mark, FIXME and TODO

While coding in Objective-C, #pragma mark is very handy for code organization in the Jump Bar. For example:

#pragma mark – Initialization 
code here...
 
#pragma mark – Table Management
more code here...

The Jump Bar would show the following, where code sections are clearly marked:

Swift #pragma alternative // MARK

#pragma mark Alternative for Swift

read more »

Wed, Aug 27
Extended File Attributes in Swift

Sergey Pershenkov sent me a note to share his open source project for BSD system functions to handle extended file attributes in Swift.

Download swift-xattr

NSDate Extensions in Swift

Melvin Rivera is the author of AFDateHelper, a sizeable list of extensions for NSDate, written in Swift.

In this open source project you’ll find extensions to compare dates, determine time interval between dates, create dates from string, among others.

The published extensions have all been tested with Xcode 6 (beta 6).

Tue, Aug 26
Introduction to iOS WKWebView

Although I’ve used UIWebView over the years, there was never a compelling reason to make it a go-to UI control. With the introduction of WKWebView, my perspective may change.

Mattt Thompson:

Boasting responsive 60fps scrolling, built-in gestures, streamlined communication between app and webpage, and the same JavaScript engine as Safari, WKWebView is one of the most significant announcements to come out of WWDC 2014

And this is intriguing:

One of the major improvements over UIWebView is how interaction and data can be passed back and forth between an app and its web content.

WKWebView sounds well worth a closer look. Mattt provides a good introduction.