Add (+) button to domain filter view

This commit is contained in:
relikd
2020-03-26 19:28:03 +01:00
parent cbec3981bb
commit 144773ddaa
5 changed files with 51 additions and 15 deletions

View File

@@ -2,19 +2,32 @@ import UIKit
// MARK: Basic Alerts
/// - Parameters:
/// - buttonText: Default: "Dismiss"
func Alert(title: String?, text: String?, buttonText: String = "Dismiss") -> UIAlertController {
let alert = UIAlertController(title: title, message: text, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: buttonText, style: .cancel, handler: nil))
return alert
}
/// - Parameters:
/// - buttonText: Default: "Dismiss"
func ErrorAlert(_ error: Error, buttonText: String = "Dismiss") -> UIAlertController {
return Alert(title: "Error", text: error.localizedDescription, buttonText: buttonText)
}
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping () -> Void) -> UIAlertController {
/// - Parameters:
/// - buttonText: Default: "Dismiss"
func ErrorAlert(_ errorDescription: String, buttonText: String = "Dismiss") -> UIAlertController {
return Alert(title: "Error", text: errorDescription, buttonText: buttonText)
}
/// - Parameters:
/// - buttonText: Default: "Continue"
/// - buttonStyle: Default: `.default`
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping (UIAlertController) -> Void) -> UIAlertController {
let alert = Alert(title: title, text: text, buttonText: "Cancel")
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action() })
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action(alert) })
return alert
}

View File

@@ -55,15 +55,11 @@ extension String {
ending = rld + "." + ending
}
return (domain: ending, host: parts.joined(separator: "."))
// var allDots = enumerated().compactMap { $1 == "." ? $0 : nil }
// let d1 = allDots.popLast() // we dont care about TLD
// guard let d2 = allDots.popLast() else {
// return (domain: self, host: nil) // no subdomains, just plain SLD
// }
// // TODO: check third level domains
//// let d3 = allDots.popLast()
// return (String(suffix(count - d2 - 1)), String(prefix(d2)))
}
/// Returns `true` if String matches list of known second level domains (e.g., `co.uk`).
func isKnownSLD() -> Bool {
let parts = components(separatedBy: ".")
return parts.count == 2 && listOfSLDs[parts.last!]?[parts.first!] ?? false
}
}