Moving extensions around
This commit is contained in:
@@ -1,26 +1,3 @@
|
||||
import UIKit
|
||||
|
||||
struct QLog {
|
||||
private init() {}
|
||||
static func m(_ message: String) { write("", message) }
|
||||
static func Info(_ message: String) { write("[INFO] ", message) }
|
||||
#if DEBUG
|
||||
static func Debug(_ message: String) { write("[DEBUG] ", message) }
|
||||
#else
|
||||
static func Debug(_ _: String) {}
|
||||
#endif
|
||||
static func Error(_ message: String) { write("[ERROR] ", message) }
|
||||
static func Warning(_ message: String) { write("[WARN] ", message) }
|
||||
private static func write(_ tag: String, _ message: String) {
|
||||
print(String(format: "%1.3f %@%@", Date().timeIntervalSince1970, tag, message))
|
||||
}
|
||||
}
|
||||
|
||||
extension UIEdgeInsets {
|
||||
init(all: CGFloat = 0, top: CGFloat? = nil, left: CGFloat? = nil, bottom: CGFloat? = nil, right: CGFloat? = nil) {
|
||||
self.init(top: top ?? all, left: left ?? all, bottom: bottom ?? all, right: right ?? all)
|
||||
}
|
||||
}
|
||||
|
||||
precedencegroup CompareAssignPrecedence {
|
||||
assignment: true
|
||||
@@ -30,6 +7,7 @@ precedencegroup CompareAssignPrecedence {
|
||||
|
||||
infix operator <-? : CompareAssignPrecedence
|
||||
infix operator <-/ : CompareAssignPrecedence
|
||||
|
||||
extension Equatable {
|
||||
/// Assign a new value to `lhs` if `newValue` differs from the previous value. Return `false` if they are equal.
|
||||
/// - Returns: `true` if `lhs` was overwritten with another value
|
||||
17
main/Extensions/Logging.swift
Normal file
17
main/Extensions/Logging.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import Foundation
|
||||
|
||||
struct QLog {
|
||||
private init() {}
|
||||
static func m(_ message: String) { write("", message) }
|
||||
static func Info(_ message: String) { write("[INFO] ", message) }
|
||||
#if DEBUG
|
||||
static func Debug(_ message: String) { write("[DEBUG] ", message) }
|
||||
#else
|
||||
static func Debug(_ _: String) {}
|
||||
#endif
|
||||
static func Error(_ message: String) { write("[ERROR] ", message) }
|
||||
static func Warning(_ message: String) { write("[WARN] ", message) }
|
||||
private static func write(_ tag: String, _ message: String) {
|
||||
print(String(format: "%1.3f %@%@", Date().timeIntervalSince1970, tag, message))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // VPNState!
|
||||
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // nil!
|
||||
let NotifyDNSFilterChanged = NSNotification.Name("PSIDNSFilterSettingsChanged") // domain: String!
|
||||
let NotifyDateFilterChanged = NSNotification.Name("PSIDateFilterSettingsChanged") // nil!
|
||||
let NotifySortOrderChanged = NSNotification.Name("PSIDateFilterSortOrderChanged") // nil!
|
||||
|
||||
26
main/Extensions/View.swift
Normal file
26
main/Extensions/View.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
import UIKit
|
||||
|
||||
extension UIView {
|
||||
func asImage(insets: UIEdgeInsets = .zero) -> UIImage {
|
||||
if #available(iOS 10.0, *) {
|
||||
let renderer = UIGraphicsImageRenderer(bounds: bounds.inset(by: insets))
|
||||
return renderer.image { rendererContext in
|
||||
layer.render(in: rendererContext.cgContext)
|
||||
}
|
||||
} else {
|
||||
UIGraphicsBeginImageContext(bounds.inset(by: insets).size)
|
||||
let ctx = UIGraphicsGetCurrentContext()!
|
||||
ctx.translateBy(x: -insets.left, y: -insets.top)
|
||||
layer.render(in:ctx)
|
||||
let image = UIGraphicsGetImageFromCurrentImageContext()
|
||||
UIGraphicsEndImageContext()
|
||||
return UIImage(cgImage: image!.cgImage!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UIEdgeInsets {
|
||||
init(all: CGFloat = 0, top: CGFloat? = nil, left: CGFloat? = nil, bottom: CGFloat? = nil, right: CGFloat? = nil) {
|
||||
self.init(top: top ?? all, left: left ?? all, bottom: bottom ?? all, right: right ?? all)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user