Nate Stedman

Joining Attributes

January 5th, 2016

Since the first release, Attributed has had a join() extension function for sequences of attributed-string-like values:

let attributedString = [
    "Unformatted ",
    UIColor.redColor().foregroundAttribute(["Red"]),
].join().attributedString

This allows for attribute-less portions in the final attributed string. In Attributed 0.3.0, the join() extension is added to sequences of attribute functions as well.

Read More

Shirley

December 30th, 2015

Shirley is a minimal request framework for Swift programs. It uses ReactiveCocoa signal producers as a unified method for asynchronous data delivery, instead of callback functions. This allows disparate responses to be unified, with a single stream-based system.

Sessions

The central type of the framework is a session, represented by the SessionType protocol. Session is a closure-based implementation, which can also be used for type erasure.

Read More

Dragging on the command line

December 23rd, 2015

Here’s drag, a small utility to enable drag & drop for files you’ve browsed to in your terminal:

It’s useful for dragging files you’ve created on the command line into a web page to upload them - for example, adding the zip files generated by carthage archive to a Github release. The window will pop up directly under the cursor’s current location, so all that you need to do is click and drag.

Drag is available as a package, or from source. It’s written in Objective-C, so it’s not tied to a specific Xcode version.

Attributed

November 3rd, 2015

Rich-text formatting on iOS and OS X is performed with the NSAttributedString class. There are two components: a string value, and a set of substring ranges, each with an associated dictionary of attributes, which are a string key paired with an arbitrary value - since this is a Foundation class, these values must be of object types. These ranges cannot overlap. In a safe manner, attributed strings could be expressed as:

typealias AttributedString = [(Character, [String:AnyObject])]

API users do not need to interact with the backing representation at a low level, however - instead, attributes can be set across a range, or set for an entire string at initialization time. For example, given a mutable attributed string with a blue background color set across the entire string, adding a blue foreground color attribute to a middle range will automatically create three separate ranges: “blue background”, “blue background & red foreground”, and “blue background” again, each associated with the proper substring.

Read More