斯坦福公开课Swift笔记3

2020-06-30  本文已影响0人  CyberDunk1997

[https://www.bilibili.com/video/BV1rb411C7eN?p=4]

1.stride

for i in stride(from:0.5 , through:15.25 , by: 0.3 ){
}

2. Computed Properties

var indexOfOneAndOnlyFaceUpCard: Int ? {
   get{
    //返回的计算值
    var foundIndex:Int?
    for index in cards.indices {
      if cards[index].isFacedUp {
        if foundIndex != nil{
            foundIndex = index
          }else{
             return nil
         }
       }
     }
      return foundIndex
   }

   set ( newValue ){
      for index in cards.indices{
        cards[index].isFaceUp = (newValue == index)
      }
   }
}

3. Access Control

4. extension

extension Int {

var arc4random : Int {
   if self > 0 {
      return Int(arc4random_uniform(Uint32(self)))
   }else if self < 0{
      return -Int(arc4random_uniform(Uint32(abs(self))))
   }else{
     return 0 
   }
  }
}
上一篇 下一篇

猜你喜欢

热点阅读