美文网首页
斯坦福公开课Swift笔记3

斯坦福公开课Swift笔记3

作者: CyberDunk1997 | 来源:发表于2020-06-30 16:55 被阅读0次

[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

  • privite
  • privite(set)
  • open
  • public

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 
   }
  }
}
  • 生成一个随机数,在0-Int之间。(let x = 5.arc4random 生成0-5之间的随机数)

相关文章

网友评论

      本文标题:斯坦福公开课Swift笔记3

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