Snippets

Oleg Chulakov Studio Seven Time ways

Updated by Владимир Самсонов

File by-ntpd.swift Added

  • Ignore whitespace
  • Hide word diff
+...
+
+import TrueTime
+
+// Фиксируем подходящее время (например запуск приложения):
+let client = TrueTimeClient.sharedInstance
+client.start()
+
+// Теперь вы можете использовать это вместо NSDate():
+let now = client.referenceTime?.now()
+
+// Чтобы заблокировать ожидание загрузки, используйте следующее:
+client.fetchIfNeeded { result in
+   switch result {
+       case let .success(referenceTime):
+           let now = referenceTime.now()
+       case let .failure(error):
+           print("Error! \(error)")
+   }
+}
+...
Updated by Владимир Самсонов

File by-user-defaults.swift Added

  • Ignore whitespace
  • Hide word diff
+...
+
+let defaults = UserDefaults.standard
+defaults.set(Date(), forKey: "lastRun")
+let lastRun = defaults.object(forKey: "lastRun") as? Date
+
+...
Updated by Владимир Самсонов

File By GPS API.swift Deleted

  • Ignore whitespace
  • Hide word diff
-...
-
-#import CoreLocation
-
-...
-
-let gps = CLLocation()
-print("gps time ", gps.timestamp)
-
-...

File by-gps-api.swift Added

  • Ignore whitespace
  • Hide word diff
+...
+
+#import CoreLocation
+
+...
+
+let gps = CLLocation()
+print("gps time ", gps.timestamp)
+
+...
Created by Владимир Самсонов

File By GPS API.swift Added

  • Ignore whitespace
  • Hide word diff
+...
+
+#import CoreLocation
+
+...
+
+let gps = CLLocation()
+print("gps time ", gps.timestamp)
+
+...
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.