Wednesday, July 16, 2014

Swift - Generics (like template in c++) [ swift programming language apple ios]

Generics (like template in c++)
“func repeat<ItemType>(item: ItemType, times: Int) -> ItemType[] {
    var result = ItemType[]()
    for i in 0..times {
        result += item
    }
    return result
}
repeat("knock", 4)”

“// Reimplement the Swift standard library's optional type
enum OptionalValue<T> {
    case None
    case Some(T)
}
var possibleInteger: OptionalValue<Int> = .None
possibleInteger = .Some(100)”


0 comments:

Post a Comment

About

Powered by Blogger.