Skip to content

Instantly share code, notes, and snippets.

View jon-1's full-sized avatar
🆗
OK

Jonathan Michael jon-1

🆗
OK
View GitHub Profile
@alfian0
alfian0 / CoreLocation+RxSwift.swift
Last active July 1, 2020 03:47
[Pure Swift Delegate] DelegateProxy<CLLocationManager, CLLocationManagerDelegate>
import Foundation
import CoreLocation
import RxSwift
import RxCocoa
class CLLocationManagerDelegateProxy: DelegateProxy<CLLocationManager, CLLocationManagerDelegate>, DelegateProxyType, CLLocationManagerDelegate {
public weak private(set) var locationManager: CLLocationManager?
public init(locationManager: CLLocationManager) {
self.locationManager = locationManager
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
func shouldPerformIntensiveUnecessaryAnimation() -> Bool {
return ProcessInfo.processInfo.thermalState != ProcessInfo.ThermalState.critical ||
!ProcessInfo.processInfo.isLowPowerModeEnabled ||
!UIAccessibilityIsReduceMotionEnabled() ||
!(UIDevice.current.batteryLevel < 10 && UIDevice.current.batteryState == .unplugged)
}