Move platform-specific extensions around

This commit is contained in:
Davide De Rosa 2019-06-21 14:39:20 +02:00
parent f2723c475d
commit 42e2c83eb5
2 changed files with 37 additions and 18 deletions

View File

@ -73,3 +73,40 @@ extension UIAlertController {
return action
}
}
extension UIView {
static func get<T: UIView>() -> T {
let name = String(describing: T.self)
let nib = UINib(nibName: name, bundle: nil)
let objects = nib.instantiate(withOwner: nil)
for o in objects {
if let view = o as? T {
return view
}
}
fatalError()
}
}
extension UITableView {
func scrollToRowAsync(at indexPath: IndexPath) {
DispatchQueue.main.async { [weak self] in
self?.scrollToRow(at: indexPath, at: .middle, animated: false)
}
}
func selectRowAsync(at indexPath: IndexPath) {
DispatchQueue.main.async { [weak self] in
self?.selectRow(at: indexPath, animated: false, scrollPosition: .middle)
}
}
}
extension UIColor {
convenience init(rgb: UInt32, alpha: CGFloat) {
let r = CGFloat((rgb & 0xff0000) >> 16) / 255.0
let g = CGFloat((rgb & 0xff00) >> 8) / 255.0
let b = CGFloat(rgb & 0xff) / 255.0
self.init(red: r, green: g, blue: b, alpha: alpha)
}
}

View File

@ -28,15 +28,6 @@ import MessageUI
import StoreKit
import PassepartoutCore
extension UIColor {
convenience init(rgb: UInt32, alpha: CGFloat) {
let r = CGFloat((rgb & 0xff0000) >> 16) / 255.0
let g = CGFloat((rgb & 0xff00) >> 8) / 255.0
let b = CGFloat(rgb & 0xff) / 255.0
self.init(red: r, green: g, blue: b, alpha: alpha)
}
}
struct Theme {
struct Palette {
var primaryBackground = UIColor(rgb: 0x515d71, alpha: 1.0)
@ -174,12 +165,3 @@ extension PoolGroup {
return ImageAsset(name: country.lowercased()).image
}
}
extension SKProduct {
var localizedPrice: String? {
let fmt = NumberFormatter()
fmt.numberStyle = .currency
fmt.locale = priceLocale
return fmt.string(from: price)
}
}