Swift有更新,语法有些不太一样,在学习的时候做了一些更改

This commit is contained in:
Kevin Jiang
2014-09-27 23:24:31 +08:00
parent 94b6c46c54
commit 425fae6ddf
4 changed files with 18 additions and 17 deletions

View File

@@ -156,7 +156,7 @@ let centerRect = Rect(center: Point(x: 4.0, y: 4.0),
```swift
extension Int {
func repetitions(task: () -> ()) {
for i in 0..self {
for i in 0..<self {
task()
}
}
@@ -217,12 +217,13 @@ someInt.square()
```swift
extension Int {
subscript(digitIndex: Int) -> Int {
subscript(var digitIndex: Int) -> Int {
var decimalBase = 1
for _ in 1...digitIndex {
while digitIndex > 0 {
decimalBase *= 10
--digitIndex
}
return (self / decimalBase) % 10
return (self / decimalBase) % 10
}
}
746381295[0]