0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Swift】処理時間を計測するクラスを作ってみた

Posted at

めっちゃ構造体

Code

struct StopWatch {
    
    var time: TimeInterval = 0
    
    private var startDate: Date = Date()
    private var endDate: Date = Date()
    
    init() {}
    
    mutating func start() {
        self.startDate = Date()
        self.time = 0
    }
    
    @discardableResult
    mutating func stop() -> TimeInterval {
        self.endDate = Date()
        self.time = self.endDate.timeIntervalSince(self.startDate)
        return self.time
    }
    
    mutating func reset() {
        self.time = 0
        self.startDate = Date()
        self.endDate = Date()
    }
}

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?