Features:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To check if a number is between a range, don't do | |
if number >=0 && number <= 100 { | |
} | |
// Use range and news operators instead : | |
if 0...100 ~= number { | |
} |
With iOS 9 Apple added a Low Power Mode to the iPhone. It extends battery life by stopping some battery heavy features such as email fetch, Hey Siri and background app refresh until you can recharge the device.
It is important to understand that it is the user who decides to enter low power mode. You need to go into the battery settings to turn it on.
To detect LPM you have to be in the couple iOS 9.X / iPhone:
- For iOS 8.X, you need test availablity before use it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Throttle { | |
static func onQueue(queue: NSOperationQueue, by timeInterval: NSTimeInterval, function: () -> ()) { | |
queue.cancelAllOperations() | |
let delayOperation = DelayOperation(timeInterval: timeInterval) | |
let throttledOperation = NSBlockOperation() { | |
function() | |
} | |
throttledOperation.addDependency(delayOperation) | |
queue.addOperations([delayOperation, throttledOperation], waitUntilFinished: false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Alamofire.Request { | |
func responseDebugPrint() -> Self { | |
return responseJSON() { | |
response in | |
if let JSON: AnyObject = response.result.value, | |
JSONData = try? NSJSONSerialization.dataWithJSONObject(JSON, options: .PrettyPrinted), | |
prettyString = NSString(data: JSONData, encoding: NSUTF8StringEncoding) { | |
print(prettyString) | |
} else if let error = response.result.error { | |
print("Error Debug Print: \(error.localizedDescription)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// #Do class - Or how to transform DispatchQueue-escaping-weakable stuff on pointer into a more readable usage | |
/// TL;DR - Usage | |
// In ViewModel/Interactor | |
Do.bg(on: self) { this in | |
this.doSomeWSCalls() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGImage { | |
var brightness: Double { | |
get { | |
let imageData = self.dataProvider?.data | |
let ptr = CFDataGetBytePtr(imageData) | |
var x = 0 | |
var result: Double = 0 | |
for _ in 0..<self.height { | |
for _ in 0..<self.width { | |
let r = ptr![0] |
NewerOlder