In this port to Swift of the great of Haskell’s “Functors, Applicatives, And Monads In Pictures” we are going to look at these functional programming concepts aided by some very helpful pictures.
Swift
Deferring and Delegating in Swift 2
We’re used to the Cocoa framework having classes that are assigned delegates from actions such as XML parsing. But what if we want to create our own types with our own delegates.
little bites of cocoa — #19: Protocol Extensions
Protocol Extensions are a new feature of Swift 2. They allow you to add new functions (complete with implementations) to any class that implements a protocol. The functionality is best explained with a simple example. Let’s say you wanted to add a way to shuffle arrays.
Should I use a Swift struct or a class?
Swift has rich value types, which is a new experience for many software developers. This has opened the door for the functionalists to ride in.
What I call “functionalism” is really the philosophy of functional programming, which is in fact a very old idea. The idea is that a lot of bugs in programming today are due to having the wrong state. For example, the Heartbleed bug happened because someone re-used the same array for a different purpose. So the solution, clearly, is to get rid of mutable arrays, and mutable variables, and the assignment operator, and you can’t have the heartbleed bug now. (Why they did not also get rid of the programmer is an exercise left to the reader.)
Swift Scripting
Unit Testing Tutorial: Mocking Objects (Swift)
RichEditorView for iOS
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing. Written in Swift 1.2 (Xcode 6.3). Supports iOS 8 through Cocoapods, or iOS 7 by including the source in your project.
SwiftyAs – Swift “as?” for Objective-C
Let me introduce: SwiftyAs. It’s a tiny little library to provide sort of the same functionality as as? from Swift in Objective-C. Let me explain…
In Swift, you can use the as? operator to safely cast a variable to another type (albeit Optional). If the actual type at runtime doesn’t match, Swift turns it into a nil, and otherwise you just get the variable as an optional.
Typed Table View Controllers Redux – Swift code snippet
let rootViewController = tableViewController([1,2,3]) { cell, num in cell.textLabel?.text = "Cell \(num)" }
How to Create Mocks and Stubs in Swift – Andrew Bancroft
Without 100% support for a mocking framework like OCMock, I found myself needing to get creative when building mock objects and method stubs in Swift unit tests. The great thing about testing is that you’re… well… testing things out to see if they’ll work, and I found a solution that I’m pretty happy with for now. I’m open to better ways, so leave a comment if you’ve had good results using a different design!