# MemoryLayout

### Size & Stride

June 16, 2017

A quick word of warning to those of you using UnsafePointer and MemoryLayout.

• The size of a type tells you how many bytes it takes to hold that type in memory.
• The stride of a type tells you how far apart each instance of the type is in memory.

If you are doing pointer arithmetic on UnsafePointer then Swift handles this for you.

If you are . . .

# Swift REPL Targets

January 22, 2017

Have you seen the message error: repl.swift:2:31: error: '<type>' is only available on OS X <version> or newer? In current releases of Xcode, the Swift REPL uses a hard-coded 10.9 target instead of the current OS.

The solution is fairly easy:

xcrun swift -target x86_64-apple-macosx10.12

Substitute whatever OS version or . . .

# Improving Optionals

### All problems can be solved by adding another protocol

January 19, 2017

Optionals are great. I've tracked down too many bugs to Objective-C's magical "messages to nil return nil"; I have no interest in going back.

But sometimes there are things you want to do with optionals or when optionals are of a specific type. Here are some of my favorites:

## isNilOrEmpty

Sometimes I don't care about the . . .

# Quick: Easy DispatchTime

### Expressin' me some literals

November 10, 2016

Here's a quick bonus post. I find using DispatchTime a bit less convenient than it should be. In a GUI application I almost always just want to specify a TimeInterval, aka number of whole or fractional seconds.

Thankfully Swift extensions can grant my heart's desire:

extension DispatchTime: ExpressibleByIntegerLiteral { public init( . . .

# Mixing Initializers

### init? init! init throws

November 09, 2016

Today is a really simple post but something people struggle with, often in the context of extensions or interacting with RawRepresentable enums.

## Can't delegate to failable initializer

Let's say you have a type with a failable initializer. Now you want to extend that type to support deserializing from JSON. You throw nice detailed . . .

# The Technical Fraternity

### Let's get real

October 13, 2016

When I read @RedQueenCoder's blog post... it really angried up my blood.

To all of you claiming knowledge of data structures is some kind of signal in interviews? Stop it.

Seriously.

It isn't reasonable to expect a candidate to derive that elegant solution it took two PhDs 8 months to discover.

Algorithm questions are not a way to . . .

# Command Line Swift

### #!/usr/bin/awesome

September 21, 2016

This post is mostly a brain dump of what it takes to use Swift for command line scripting.

Update: I've added -S to env. This makes things compatible with recent versions of FreeBSD. There doesn't appear to be a portable solution for Linux because it treats the entire line after the first space as a single argument rather than . . .