美文网首页
The Swift Programming Language--

The Swift Programming Language--

作者: ted005 | 来源:发表于2015-06-18 22:03 被阅读20次

Collection Types

  • Array

    Bridge with NSArray

    Type:
    **Array<T> / [T] **, [T] is preferred
    //Empty array
    var arr1: [Int] = Int
    var arr2: [Int] = []

    //Using initializer
    var arr3: [Double] = [Double](count: 3, repeatedValue: 0.0)
    
    //properties & methods
    arr3.count // 3
    arr3.append(2.0) 
    arr3.isEmpty
    arr3[0]
    arr3[0...3] = [1.0, 2.0] //the first fout elements will be replaced
    arr3.insert(3.0, atIndex: 0)
    arr3.removeAtIndex(0)
    arr3.removeLast()
    
    for i in arr3[0..<arr3.count] {
        //TODO
    }
    
    for (index, value) in arr3.enumerate() {
        //TODO
    }
    
  • Set

Bridge with NSSet

相关文章

网友评论

      本文标题:The Swift Programming Language--

      本文链接:https://www.haomeiwen.com/subject/lbysqttx.html