标签:and 使用 list ace 截取 random numbers bsp convert
1. 截取列表值 (前几个)
/// let numbers = [1, 2, 3, 4, 5]
/// print(numbers.prefix(2))
/// // Prints "[1, 2]"
/// print(numbers.prefix(10))
/// // Prints "[1, 2, 3, 4, 5]"
2. 截取列表值 (后几个)
/// let numbers = [1, 2, 3, 4, 5]
/// print(numbers.suffix(2))
/// // Prints "[4, 5]"
/// print(numbers.suffix(10))
/// // Prints "[1, 2, 3, 4, 5]"
3. 获取一个随机的元素
let numbers = [1, 2, 3, 4, 5]
let number = numbers.randomElement()
标签:and 使用 list ace 截取 random numbers bsp convert
原文地址:https://www.cnblogs.com/luobenpaidui/p/13273581.html