美文网首页
Swift_集合 let element = arr.first

Swift_集合 let element = arr.first

作者: Eyes_cc | 来源:发表于2020-12-16 11:13 被阅读0次
    /// The first element of the collection.
    ///
    /// If the collection is empty, the value of this property is `nil`.
    ///
    /// - Complexity: O(1)
        @inlinable public var first: Element? { get }
    
    let numbers = [10, 20, 30, 40, 50]
    if let firstNumber = numbers.first {
        print(firstNumber)
    }
    // Log: 10
    
    /// The last element of the collection.
    ///
    /// If the collection is empty, the value of this property is `nil`.
    ///
    /// - Complexity: O(1)
        @inlinable public var last: Element? { get }
    
    let numbers = [10, 20, 30, 40, 50]
    if let lastNumber = numbers.last {
        print(lastNumber) 
    }
    // Log: 50
    

    相关文章

      网友评论

          本文标题:Swift_集合 let element = arr.first

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