原创Blog,转载请注明出处
blog.youkuaiyun.com/hello_hwc
前言:和OC不同,Swift有很多全局的函数,这些全局函数对简化代码来说很有用,目前Swift出到了2.0,不过我这篇文章还是用Swift1.2写的示例代码。
Count-统计数量
文档
func count<T : _CollectionType>(x: T) -> T.Index.Distance
Description
Return the number of elements in x.
O(1) if T.Index is RandomAccessIndexType; O(N) otherwise.
示例
let arr = [1,2,3,4]
let dic = [1:2,"a":"b"]
let str =