Monthly Archives: June 2014

Understanding Swift’s reduce Method

Swift’s API includes many functions and instance methods that reflect its functional programming heritage. A prime example is called reduce.  You can reduce a collection of values down to just one value, such as calculating the sum of every person’s age in an array of … Continue reading

Posted in Swift | Tagged , | 7 Comments

Create a Swift Dictionary from an Array

Here is a Gist I posted showing a Swift utility function that enables you to create a Dictionary containing an optional entry for every element in an Array. It uses the reduce function to create one Dictionary from every element in … Continue reading

Posted in Swift | Tagged , , | 2 Comments

Cross-join two Swift arrays

Here is a Gist I just published on GitHub of a utility function that performs a cross-join between two Swift arrays. This allows you to iterate over one array for every element in another array, and return an optional value built for … Continue reading

Posted in Swift | Tagged , , | 1 Comment

Randomly shuffle a Swift array

I just posted a Gist on GitHub that shows how to add a shuffle method to Swift’s Array class, which randomizes the order of an array’s elements. My shuffle method relies on the arc4random function, which means that the file containing that extension … Continue reading

Posted in Swift | Tagged , , | 3 Comments

Swift Case Study: Histograms

This article examines a program written in Swift that creates text-based histogram renderings. The purpose of this case study is to show how such a program can leverage features found in the initial pre-release version of Swift. The Xcode 6 project … Continue reading

Posted in Swift | 2 Comments

Curried Functions in Swift

Apple’s programming language Swift includes several features commonly used in functional programming but unheard of in more mainstream languages. This blog post explores the lesser-known feature known as curried functions. I first encountered currying when studying the functional language Haskell, … Continue reading

Posted in Swift | Tagged , | 19 Comments

Instantiating Classes by Name in Swift

This article demonstrates how to create a Swift class instance based solely on the class name and possibly an argument for its initializer method. It relies on Objective-C interop to perform the actual object creation, which is hidden behind a generic … Continue reading

Posted in Swift | Tagged | 16 Comments

Ruminations on Swift

It’s been awhile since I have found anything worth blogging about in the iOS development world. The first day of WWDC 2014 changed all that. Had Apple only announced their new programming language, Swift, that would have been enough to … Continue reading

Posted in Swift | 13 Comments