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 Foundation | |
import WebKit | |
final class WebCacheCleaner { | |
class func clean() { | |
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast) | |
print("[WebCacheCleaner] All cookies deleted") | |
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records 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
class GoogleTestViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let webView = WKWebView.init(frame: self.view.frame) | |
webView.load(URLRequest.init(url: URL.init(string: "https://www.google.com")! )) | |
self.view.addSubview(webView) | |
} |
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
// Douglas Hill, December 2018 | |
import UIKit | |
/// A table view that allows navigation and selection using a hardware keyboard. | |
/// Only supports a single section. | |
class KeyboardTableView: UITableView { | |
// These properties may be set or overridden to provide discoverability titles for key commands. | |
var selectAboveDiscoverabilityTitle: String? | |
var selectBelowDiscoverabilityTitle: String? |
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
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
if #available(iOS 10.0, *) { | |
UNUserNotificationCenter.current().delegate = self | |
} | |
return true | |
} |
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 URLComponents { | |
init(scheme: String = "https", host: String, path: [String], queries: [URLQueryItem]?) { | |
self = URLComponents.init() | |
self.scheme = scheme | |
self.host = host | |
var p = path | |
p.insert("/", at: 0) | |
self.path = NSString.path(withComponents: p) | |
self.queryItems = queries | |
} |
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 Foundation | |
class MockURLProtocol: URLProtocol { | |
static var requestHandler: ((URLRequest) throws -> (HTTPURLResponse, Data) )? | |
override class func canInit(with request: URLRequest) -> Bool { | |
return true | |
} | |
override class func canonicalRequest(for request: URLRequest) -> URLRequest { | |
return 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
#if MOCK_URL_PROTOCOL | |
let configuration = URLSessionConfiguration.ephemeral | |
configuration.protocolClasses = [MockURLProtocol.self] | |
let urlSession = URLSession(configuration: configuration) | |
#else | |
let urlSession = URLSession.shared | |
#endif |
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 employeeInfo = """ | |
{ | |
"employeeID":156789, | |
"name": "Harris Smith" | |
} | |
""" | |
MockURLProtocol.requestHandler = { request in | |
let response = HTTPURLResponse.init(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)! | |
return (response,employeeInfo.data(using: .utf8)!) | |
} |
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
class EmployeeInfoRequest { | |
#if MOCK_URL_PROTOCOL | |
class iMockURLProtocol: MockURLProtocol { | |
override func startLoading() { | |
iMockURLProtocol.requestHandler = { request in | |
let response = HTTPURLResponse.init(url: request.url!, statusCode: 200, httpVersion: "2.0", headerFields: nil)! | |
return (response,mockEmployeeInfoData) | |
} | |
super.startLoading() |
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
protocol APIRequest { | |
func mockURLProtocolClass() -> AnyClass? | |
} | |
extension APIRequest { | |
func mockURLProtocolClass() -> AnyClass? { | |
return nil | |
} | |
} |
OlderNewer