可以使用數組的isEmpty屬性來判斷一個數組是否為空。如果數組中沒有任何元素,該屬性會返回true,否則返回false。例如:
let array = [Int]() if array.isEmpty { print("數組為空") } else { print("數組不為空") }
輸出結果為"數組為空"。