【使用】:返回指定值在集合中最后一次出现的索引。
值得注意的是:element在数组中有可能不存在,此时会返回nil。
/// Returns the last index where the specified value appears in the collection.
/// : 返回指定值在集合中最后一次出现的索引。
//
/// After using `lastIndex(of:)` to find the position of a particular element
/// in a collection, you can use it to access the element by subscripting.
/// This example shows how you can modify one of the names in an array of
/// students.
// : 在使用' lastIndex(of:) '查找集合中特定元素的位置之后,可以使用它通过下标访问或修改元素。这个示例展示了如何修改学生数组中的一个名称。
///
/// var students = ["Ben", "Ivy", "Jordell", "Ben", "Maxime"]
/// if let i = students.lastIndex(of: "Ben") {
/// students[i] = "Benjamin"
/// }
/// print(students)
/// // Prints "["Ben", "Ivy", "Jordell", "Benjamin", "Max"]"
///
/// - Parameter element: An element to search for in the collection.
/// - Returns: The last index where `element` is found. If `element` is not
/// found in the collection, returns `nil`.
// :在集合中找到element时,返回下标,否则返回nil.
///
@inlinable public func lastIndex(of element: Element) -> Int?
网友评论