close

在一般的程式語言中, Bool 通常只是型態(type), 經由判斷式如 if 等產生true 或 false.

而在 Swift 則可以用Bool() 直接判斷並得到 true 或 false.

ex:

let sample = 4

let a = Bool(sample%4)   // 結果 a 是 false, 因為沒餘數.

or 

let a = Bool(sample%2)    //結果 a 也是 false.

or 

let a = Bool(sample%1)    // 結果 a 也是 false.

or

let a = Bool(sample%0)    // error.

or

let a = Bool(sample%3)  // 得到 a 是 true, 因為有餘數, 所以是 true. 除了1,2,4 外應該其他 a 都是 true 了.

arrow
arrow
    文章標籤
    Swift iOS
    全站熱搜

    小明學iOS 發表在 痞客邦 留言(0) 人氣()