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