2

I have a java app that uses SystemClock.upTimeMillis(), but now I am trying to replicate the code in Swift (New apple language) for the same app on iOS using the same concepts.

I need to get the clock to reset the seconds to 00 once it reaches 60, and the minutes to carry on going, then the minutes to reset to 00 and hours to carry on going, just to get a clock going (as my app uses a clock like interface).

So I need the Swift / Objective C version of SystemClock.uptimeMillis().

Is it possible? or how can I get the clock working the like a normal clock?

3 Answers3

3
[[NSProcessInfo processInfo] systemUptime]

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSProcessInfo_Class/Reference/Reference.html#//apple_ref/occ/instm/NSProcessInfo/systemUptime

awph
  • 566
  • 6
  • 15
0

The closest thing you'll find is probably NSDate which returns and stores a time with sub second accuracy.

David Berry
  • 40,941
  • 12
  • 84
  • 95
0

Swift would be like this:

import Foundation

var systemUptime: NSTimeInterval {
    return NSProcessInfo.processInfo().systemUptime
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571