【使用】:一个Bool值,指示集合是否为空。
值得注意的是:字符串是字符的集合,也遵循了RandomAccessCollection。
/// When you need to check whether your collection is empty, use the `isEmpty` property instead of checking that the `count` property is equal to zero. For collections that don't conform to `RandomAccessCollection`, accessing the `count` property iterates through the elements of the collection.
// :当你需要检查集合是否为空时,使用' isEmpty '属性代替检查,而不是检查' count '属性等于零。对于不符合“RandomAccessCollection”的集合,访问“count”属性将遍历集合的元素。
///
/// let horseName = "Silver"
/// if horseName.isEmpty {
/// print("I've been through the desert on a horse with no name.")
/// } else {
/// print("Hi ho, \(horseName)!")
/// }
/// // Prints "Hi ho, Silver!")
///
@inlinable public var isEmpty: Bool { get }
网友评论