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 WebKit | |
extension WKWebView { | |
/// Quick and short load URL String in a WKWebView | |
func load(_ string: String) { | |
if let url = URL(string: string) { | |
let request = URLRequest(url: url) | |
load(request) | |
} | |
} |
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 String { | |
/// Quick convert `String` to `URL` | |
/// # Usage | |
/// let url = String.toURL | |
func toURL() -> URL { | |
return URL(string: self)! | |
} | |
/// Get the name of a file, from a `Sring`, without path or file extension | |
/// # Usage | |
/// let path = "/dir/file.txt" |
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
// WebView Observers | |
var webViewURLObserver: NSKeyValueObservation? // Observer for URL | |
var webViewTitleObserver: NSKeyValueObservation? // Observer for Page Title | |
var webViewProgressObserver: NSKeyValueObservation? // Observer for Load Progress | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// OBSERVER: WebView URL | |
webViewURLObserver = webView.observe(\.url, options: .new) { [weak self] webView, change in |
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
var webViewURLObserver: NSKeyValueObservation? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
webViewURLObserver = webView.observe(\.url, options: .new) { [weak self] webView, change in | |
let url = "\(String(describing: change.newValue))" | |
self?.urlDidChange(urlString: url) | |
} | |
} |
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
var webViewTitleObserver: NSKeyValueObservation? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
webViewTitleObserver = webView.observe(\.title, options: .new) { [weak self] webView, change in | |
if let title = change.newValue as? String { | |
self?.titleDidChange(pageTitle: title) | |
} | |
} |
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
var webViewProgressObserver: NSKeyValueObservation? | |
@IBOutlet var progressBar: UIProgressView! // iOS Progress Bar | |
@IBOutlet var progressBar: NSProgressIndicator! // macOS Progress Spinner | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
webViewProgressObserver = webView.observe(\.estimatedProgress, options: .new) { [weak self] webView, change in | |
self?.progressDidChange(progress: change.newValue ?? 1.0) |
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
let Defaults = UserDefaults.standard | |
struct Settings { | |
static let firstLaunch = Defaults.bool(forKey: Keys.firstLaunch) | |
static let totalLaunches = Defaults.integer(forKey: Keys.totalLaunches) | |
} | |
struct Keys { | |
static let firstLaunch = "FirstLaunchKey" | |
static let totalLaunches = "TotalLaunchesKey" |
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 UIColor { | |
static func color(_ red: Int, green: Int, blue: Int, alpha: Float) -> UIColor { | |
return UIColor( | |
red: 1.0 / 255.0 * CGFloat(red), | |
green: 1.0 / 255.0 * CGFloat(green), | |
blue: 1.0 / 255.0 * CGFloat(blue), | |
alpha: CGFloat(alpha)) | |
} | |
} |
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
@IBOutlet var progressBar: NSProgressIndicator! // Progress Bar Object | |
var progressValue = 0.0 // Progress Bar Value (Double) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
progressBar.doubleValue = progressValue | |
startProgressLoader() | |
} |
OlderNewer