美文网首页
Swift_集合的isEmpty属性

Swift_集合的isEmpty属性

作者: Eyes_cc | 来源:发表于2020-03-17 14:51 被阅读0次

【使用】:一个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 }

相关文章

网友评论

      本文标题:Swift_集合的isEmpty属性

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