Matt Gallagher: Cocoa with Love

Articles about Swift, Cocoa, software design and programming.

  • Oct 25, 2016

    Testing actions over time

    Testing that actions are scheduled correctly over time is a pain. I'll show a way to test events scheduled over time, threads and other execution contexts with a "Debug Context Coordinator" that functions as a basic task scheduler but operates over a simulated version of time so that testing of invocation times and task interaction can be precise and free from changes due to host activity.

    asynchronytesting

    Read article

  • Oct 14, 2016

    Specifying function execution contexts

    I take a look at what's involved in specifying the 'execution context' in which a function should be invoked. It's a complicated task due to how broad the term 'execution context' can be, as well as the fact that both function caller and function callee may have conflicting desires for how a function should be invoked.

    asynchrony

    Read article

  • Sep 22, 2016

    Optimizing a copy-on-write double-ended queue in Swift

    I present an implementation of a a double-ended queue type (deque) in Swift and look at what is required to implement copy-on-write in an optimized way so that this double-ended queue is faster than Array when used as a first-in-first-out (FIFO) queue.

    Swiftfundamentals

    Read article

  • Aug 23, 2016

    Values and errors, part 2: eight languages compared

    A concrete look at the languages studied by the Swift developers when designing Swift's approach to error handling. By comparing these to Swift, I'll try to better understand what balance the Swift developers sought on the topics of feature complexity, syntactic efficiency, abstraction, information signalling and safety.

    Swifterror handling

    Read article

  • Aug 21, 2016

    Values and errors, part 1: 'Result' in Swift

    In this article, I'll discuss the Result type in Swift as well as common variations in implementation and approach used for this data type. I'll also look at *why* the type was rejected for inclusion in the standard library and what effect that rejection is likely to have.

    Swiftfundamentalserror handling

    Read article

  • Jul 30, 2016

    Design patterns for safe timer usage

    I look at usage patterns around timers including some problematic approaches that can make refactoring more difficult, cause strange bugs and otherwise create problems for maintainability.

    asynchrony

    Read article

  • Jul 12, 2016

    Exponential time complexity in the Swift type checker

    One of the most annoying problems in Swift is when the compiler gives an 'Expression was too complex to be solved in a reasonable time' error. I look at why this error occurs, how to avoid it and talk about how this should be solved in a future compiler update.

    Swiftcompiler

    Read article

  • Jun 25, 2016

    Parsing whitespace in an Xcode extension

    Fun with a pushdown automaton (implemented as a single mighty switch statement) for parsing whitespace in Swift source files. The result is an Xcode 8 Source Editor Command extension for detecting and correcting whitespace issues in Swift files.

    SwiftparsingXcode

    Read article

  • Jun 2, 2016

    Mutexes and closure capture in Swift

    I'm going to talk about the absence of any threading or thread synchronization language features in Swift and the concurrency proposal for Swift's future. I'll also try to get a wrapper around different mutex machinery to perform optimally.

    Swiftasynchrony

    Read article