Skip to content

Instantly share code, notes, and snippets.

enum Coin: Double {
case Penny = 0.01
case Nickel = 0.05
case Dime = 0.1
case Quarter = 0.25
}
let wallet: [Coin] = [.Penny, .Nickel, .Dime, .Dime, .Quarter, .Quarter, .Quarter]
var count: Int = 0
protocol FullyNameable {
var fullName: String { get }
}
struct User: FullyNameable {
var fullName: String
}
let user = User(fullName: "John Smith")
protocol Printable {
func description() -> String
}
protocol PrettyPrintable: Printable {
func prettyDescription() -> String
}
struct User: PrettyPrintable {
let name: String
import UIKit
struct Point {
let x: Int
let y: Int
}
struct Map {
static let origin: Point = Point(x: 0, y: 0)
import UIKit
//struct Rectangle {
// var length: Int
// var width: Int
//
// var area: Int {
// return length * width
// }
//}
//: Playground - noun: a place where people can play
import UIKit
enum ReadingMode {
case Day
case Evening
case Night
var statusBarStyle: UIStatusBarStyle {
import UIKit
class ReadItLaterClient {
lazy var session: NSURLSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
/* Do the rest of the work */
}
@thanhluu
thanhluu / Higher Order Functions.swift
Last active May 19, 2016 16:37
Higher Order Functions
func printString(aString: String) {
print("Printing the string passed in: \(aString)")
}
printString("Hi, my name is Thanh")
let someFunction: String -> Void = printString
someFunction("Hi, look at me!")
/*****************/
@thanhluu
thanhluu / Closure Expressions.swift
Created May 19, 2016 16:38
Closure Expressions
func doubler(i: Int) -> Int {
return i * 2
}
let doubleFunction = doubler
doubleFunction(2)
let numbers = [1,2,3,4,5]
let doubleNumbers = numbers.map(doubleFunction)
@thanhluu
thanhluu / Standard Library Functions.swift
Last active May 26, 2016 15:16
Standard Library Functions
let values = [1,2,3,4,5]
var newArray = [Int]()
for number in values {
newArray.append(number * 2)
}
let tripledValues = values.map { $0 * 3 }
// Map