This file contains hidden or 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 | |
class Debouncer { | |
private let queue: DispatchQueue | |
private var task: DispatchWorkItem? | |
private(set) var hasPerformedWorkAfterCancel = false // helper property which is needed for some use cases to understand if the work was done | |
init(queue: DispatchQueue = DispatchQueue.main) { | |
self.queue = queue | |
} |
This file contains hidden or 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 UIKit | |
class InsetLabel: UILabel { | |
private let topInset: CGFloat | |
private let leftInset: CGFloat | |
private let bottomInset: CGFloat | |
private let rightInset: CGFloat | |
init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) { |
This file contains hidden or 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 UIKit | |
class GradientLayeredView: UIView { | |
enum GradientDirection { | |
case leftToRight | |
case rightToLeft | |
case topToBottom | |
case bottomToTop | |
} |
This file contains hidden or 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
#In your Xcode target project settings select the "Build phases" tab. | |
#Click the "+" button add select "New Run Script Phase" | |
#In the script area paste this tiny script which will increment the bundle version every time the project is built: | |
#!/bin/bash | |
# This script takes the build number from the release target plist, increments and then saves back | |
bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PRODUCT_SETTINGS_PATH}") | |
bN=$(($bN + 1)) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "${PRODUCT_SETTINGS_PATH}" |
This file contains hidden or 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 UIApplication { | |
class func tryURL(urls: [String]) { | |
let application = UIApplication.shared | |
for url in urls { | |
guard let url = URL(string: url) else { | |
continue | |
} | |
if application.canOpenURL(url) { | |
application.open(url, options: [:], completionHandler: nil) | |
return |
This file contains hidden or 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 UIKit | |
extension UIColor { | |
func shadeColor(factor: CGFloat) -> UIColor { | |
var r: CGFloat = 0 | |
var g: CGFloat = 0 | |
var b: CGFloat = 0 | |
var a: CGFloat = 0 | |
let t: CGFloat = factor < 0 ? 0 : 1 |
This file contains hidden or 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 UIKit | |
extension UIColor { | |
convenience init(hex: String) { | |
let scanner = Scanner(string: hex) | |
scanner.scanLocation = 0 | |
var rgbValue: UInt64 = 0 | |
scanner.scanHexInt64(&rgbValue) |