LoginSignup
22
21

More than 5 years have passed since last update.

swiftはかわいい

Last updated at Posted at 2014-06-05

アップルさんのswiftはかわいいよ

こんなことも簡単にできちゃうね

swift
protocol FakeRuby {
    func times(block:()->())
}

extension Int:FakeRuby {
    func times(block:()->()) {
        for i in 0..self {
            block()
        }
    }
}

10.times {
    println("ルビーじゃないよ")
}

追記:それでも自分は甘かったよ、もっと簡潔にできるw

swift
extension Int {
    var hours:Int {
        return self * 3600
    }
    var ago:Int {
        return -self
    }
    func times(block:()->()) {
        for i in 0..self {
            block()
        }
    }
}

7.hours
7.hours.ago
7.times {
    println("hello")
}
22
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
21