- Code tends to be shorter & clearer
- Value types are a super valuable design pattern (see what I did there)
- Optionals are amazing
- Online resources tend to be in Swift these days
- Swift 2 is a lot better than Swift 1.2
- Trending towards stability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
var name: String | |
} | |
let currentUser = MutableProperty(User(name: "Foo")) | |
currentUser[\.name] <~ nameTextField.reactive.textValues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let text = """ | |
Hello | |
World | |
""" | |
extension String { | |
var lines: AnySequence<Substring> { | |
let string = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here is a usage example. Refer to ImagePicker.swift below for the implementation! | |
// 1. Easily configure the picker | |
let cameraPicker = ImagePicker(sourceType: .camera) | |
let cropPicker = ImagePicker(sourceType: .photoLibrary, allowsEditing: true) | |
// Automatically includes both kUTTypeImage and kUTTypeLivePhoto | |
let livePhotoPicker = ImagePicker(sourceType: .photoLibrary, mediaTypes: [.livePhotos]) | |
// 2. Use the picker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
enum URLResult { | |
case response(Data, URLResponse) | |
case error(Error, Data?, URLResponse?) | |
} | |
extension URLSession { | |
@discardableResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BitMask<T: FixedWidthInteger>: RandomAccessCollection { | |
typealias SubSequence = BitMask<T> | |
var rawValue: T { | |
var rawValue: T = 0 | |
for bit in self { | |
rawValue |= bit | |
} | |
return rawValue | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prints out all the unicode scalars in a Foundation CharacterSet. | |
// | |
// Compile: swiftc -O scalars.swift | |
// Run: ./scalars <character set name> | |
import Foundation | |
extension UnicodeScalar { | |
static var allScalars: AnySequence<UnicodeScalar> { | |
let numbers = sequence(first: 0, next: { $0 + 1 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Dispatch | |
/// Wraps some `Base` type so that all method calls become | |
/// "message sends", e.g., `async { $0.foo() }` or `sync { $0.bar() }`. | |
public final class Actor<Base> { | |
private var instance: Base | |
private let queue: DispatchQueue | |
public init(_ instance: Base, target: DispatchQueue? = nil) { | |
self.instance = instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
enum Signal: Int32 { | |
case HUP = 1 | |
case INT = 2 | |
case QUIT = 3 | |
case ABRT = 6 | |
case KILL = 9 | |
case ALRM = 14 | |
case TERM = 15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class GreetingFeature: Feature { | |
override func scenarios() { | |
Scenario("Greeting on first load") | |
.Given("the app has launched") | |
.Then("the text 'Hello, world!' is on screen") | |
} | |
} |