Getting system uptime in iOS/Swift

前端 未结 4 1192
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 00:03

Is there a way to get system uptime in iOS (using Swift)? What I need is to measure time without having to worry about the user changing the time. In Android there\'s a

4条回答
  •  [愿得一人]
    2020-12-10 00:27

    This is a solution in Swift 4.

     var boottime = timeval()
     var size = MemoryLayout.stride
     sysctlbyname("kern.boottime", &boottime, &size, nil, 0) 
    

提交回复
热议问题