[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之间的随机数)
网友评论