Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.

Swift Code Library

This page contains links to blogposts that contain general purpose Swift code.

minmax and clippedMinMax

Two functions that go beyond the standard 'min' and 'max' functions.


A child of NSView that handles the separation of "mouseUp" into "handleSingleClick", "handleDoubleClick" and "handleTripleClick". Simply derive your view from BRMouseUpView instead of NSView to have instant handling of single, double and triple mouse clicks (on the mouse up side). Or use as a code base for your own implementation.

OSX Receipt Validation in Swift

This is a complete example on all the necessary steps to add receipt validation to an OS-X project. It is a series of articles in 7 parts, the above link links to the introduction. There is an additional part 8 that shows how to use Receigen with Swift.

Mergeable Notifications

A notification wrapper class that handles the sending of notifications including a safe merge mechanism that collects multiple notifications into a single notification to prevent notification storms.

Multi Staged file reading with NSStream

This code example shows how to implement multi staged file reading using NSStream (NSInputStream) from Swift. Multi staged file reading is useful when first a file header must be read, and then only a part of the data.

Session Persistence in Swift

This code sample shows how I create/store/read session persistence data without a specific initialisation cycle. It also shows how to access the Application Support directory.

ASCII character definitions in Swift

A complete definition of all ASCII characters in Swift (typealias ASCII = UInt8). Includes a few functions and extensions to test for different type of characters.

Replacement for the FD_SET, FD_CLR, FD_ISSET and FD_ZERO macro's

These C-macro's can easily be replaced with the Swift functions in this post.

A byte buffer class providing UnsafeBufferPointer access

The UnsafeBufferPointer is one of the more beautiful pointer types in Swift. It combines the power of a collection to the sleekness of a pointer.

Printing a collection type with separators in between

Creating a description from a collection type with a separator. Without using the endIndex or Self.Index.


A simple 24h wallclock time for easier handling of the time within a day.

Nil coalescing assignment

This should be in the language itself, but it is an easy addition to make ourselves.


Update a given progress bar and label with data, while making sure that each update is viewable by the user for a minimum time.

No comments:

Post a Comment