Skip to content

Instantly share code, notes, and snippets.

@stulevine
Created February 25, 2017 13:20
Show Gist options
  • Save stulevine/4a63d418e3f90fe1039bcf2613cff76b to your computer and use it in GitHub Desktop.
Save stulevine/4a63d418e3f90fe1039bcf2613cff76b to your computer and use it in GitHub Desktop.
Swift using maps and CustomStringConvertible
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
let a = ["a", "b", "c"]
let b = ["d", "e", "f"]
let c = ["g", "h", "i"]
let aa = [a, b, c]
let m = aa.map { (a) -> [String] in
a.map({ (s) -> String in
s + " xxx"
})
}
print(m)
print(aa)
let r = ["a", "b", "c"].reduce("", { $0 + $1 } )
print(r)
class thing: CustomStringConvertible {
var name: String?
var isGood: Bool?
init(name: String, good: Bool) {
self.name = name
isGood = good
}
var description: String {
return "Name: \(name ?? ""), Good: \(isGood ?? false)"
}
}
let things = [thing(name: "one", good: true), thing(name: "two", good: false), thing(name: "three", good: true)]
print(things)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment