代码之家  ›  专栏  ›  技术社区  ›  Linh Dao

Swift 4.2:以下声明是什么意思

  •  -5
  • Linh Dao  · 技术社区  · 8 年前

    我对swift和IOS还不熟悉,所以有很多未知的东西。以下声明是什么意思?

    private let _digest: (UInt64, UInt64)

    4 回复  |  直到 8 年前
        1
  •  2
  •   Rakesha Shastri    8 年前

    它是一个 . 运算符后跟索引。

    _digest.0
    _digest.1
    

    但是,如果您想使用名称而不是索引来访问它们,也可以这样做(您仍然可以使用索引访问它)

    private let _digest: (first: UInt64, second: UInt64)
    
    _digest.first
    _digest.second
    

    Tuples .

        2
  •  0
  •   Scriptable    8 年前

    这是类型为的私有常量 tuple ,其中包含两个UInt64值。

    你可以阅读有关元组和其他类型的Swift here

    举个例子:

    let someTuple: (Double, Double) = (3.14159, 2.71828)
    

    print(someTuple.0) // 3.14159
    
        3
  •  0
  •   Jad Ghadry    8 年前

    基本上你要做的是声明一个常量变量-因为关键字 let -呼叫 _digest 类型 (UInt64, UInt64) 对它来说,这是一个 有两个类型的变量 UInt64 .

        4
  •  0
  •   Rizwan    8 年前

    tuple 那有两个 UInt64 .

    let person = ("John", "Smith")
    
    var firstName = person.0 // John
    var lastName = person.1 // Smith
    

    另外,如果需要,可以通过名称而不是索引来访问这些元素。

    var person = (fName:"John", lName:"Smith", age:Int())
    person.age = 33
    print(person.fName) // John
    print(person.lName) // Smith
    print(person.age) // 33
    

    "tuple", 1, true) 将是 type (String, Int, Bool) .

    here