Skip to content

Instantly share code, notes, and snippets.

@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!")
/*****************/
import UIKit
class ReadItLaterClient {
lazy var session: NSURLSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
/* Do the rest of the work */
}
//: Playground - noun: a place where people can play
import UIKit
enum ReadingMode {
case Day
case Evening
case Night
var statusBarStyle: UIStatusBarStyle {
import UIKit
//struct Rectangle {
// var length: Int
// var width: Int
//
// var area: Int {
// return length * width
// }
//}
import UIKit
struct Point {
let x: Int
let y: Int
}
struct Map {
static let origin: Point = Point(x: 0, y: 0)
protocol Printable {
func description() -> String
}
protocol PrettyPrintable: Printable {
func prettyDescription() -> String
}
struct User: PrettyPrintable {
let name: String
protocol FullyNameable {
var fullName: String { get }
}
struct User: FullyNameable {
var fullName: String
}
let user = User(fullName: "John Smith")
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
class Address {
var streetName: String?
var buildingNumber: String?
var apartmentNumber: String?
}
class Residence {
var address: Address?
}
class Point {
var x: Int
var y: Int
init(x: Int, y: Int){
self.x = x
self.y = y
}
}