Skip to content

Instantly share code, notes, and snippets.


Dragos Dobrean dobreandl

View GitHub Profile
View InitWebView.swift
private func configureWebView() {
let wkWebConfig = WKWebViewConfiguration() // We create a web view configuration
let wkUserController = WKUserContentController() // We create a user content controller for adding the JS for manipulating the CSS of the web page
wkWebConfig.userContentController = wkUserController
addHideHeaderScript(wkWebController: wkUserController) // We add the the hide header script
// We configure the web view, and add it as a subview to the current view
webView = WKWebView(frame: self.view.bounds, configuration: wkWebConfig)
View AddJSToWebView.swift
private func addPageHasChangedDelegateScript(wkWebController: WKUserContentController) {
// load the script from the file and create a WKUserScript object
let scriptURL = Bundle.main.path(forResource: Constants.detectPageChangeScript, ofType: "js")
let scriptContent = try! String.init(contentsOfFile: scriptURL!)
let script = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: false)
// Add the script to the WKUserContentController
// Register for receiving callbacks from javascript for a notification name
View JSWebViewDelegate.swift
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if ( == “notification_name”) {
print("Page changed")
View ChangeRootViewController.swift
let startupViewController = StartupViewController()
let navController = UINavigationController(rootViewController: startupViewController)
appDelegate.window.rootViewController = navController
xcodebuild -list -project <your_project_name>.xcodeproj
View xcodebuild-build-test
xcodebuild -workspace <your_project_name>.xcworkspace -scheme <your_desired_schema> -configuration <your_desired_configuration> -destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch),OS=10.2' -derivedDataPath <derived_data_path> BUILD_DIR=<build_directory_path> -UseModernBuildSystem=YES clean build -enableCodeCoverage=YES test
View xcodebuild-and-test
xcodebuild -workspace <your_project_name>.xcworkspace \
-scheme <your_desired_schema> -configuration <your_desired_configuration> \
-destination 'platform=iOS Simulator,name=iPad Pro (12.9-inch),OS=10.2' \
-derivedDataPath <derived_data_path> BUILD_DIR=<build_directory_path> \
-UseModernBuildSystem=YES clean build -enableCodeCoverage=YES test
View llvm-cov-show
xcrun llvm-cov show -instr-profile <path_of_the_Coverage.profdata_file> \
<path_of_the_executable> > <name_of_the_report_file>