Skip to content

Instantly share code, notes, and snippets.

View pkuecuekyan's full-sized avatar

Philipp Kuecuekyan pkuecuekyan

View GitHub Profile
@pkuecuekyan
pkuecuekyan / SearchContainerInTabBar.swift
Last active March 23, 2021 14:54
Set up a UISearchContainerViewController inside a UITabBar for tvOS 9
func setupTabBarWithSearchContainerView() {
// configure a UIViewController to display search results
// needs to conform to the UISearchResultsUpdating protocol
let searchResultsViewController = SearchResultsViewController()
// setup UISearchController and hook up to search results UIViewController
let searchController = UISearchController(searchResultsController: searchResultsViewController)
searchController.searchResultsUpdater = searchResultsViewController
searchController.hidesNavigationBarDuringPresentation = false
@pkuecuekyan
pkuecuekyan / WKWebViewSizeToFit.swift
Last active March 12, 2024 11:37
Adjust height of WKWebView frame based on scrollHeight of the webView's content
// Since the WKWebView has no sizeToFit() method, increase the frame height of the webView to
// match the height of the content's scrollHeight
//
// The WKWebView's `navigationDelegate` property needs to be set for the delegate method to be called
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if webView.isLoading == false {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
if let height = result as? CGFloat {
@pkuecuekyan
pkuecuekyan / XCUIElement+ClearText.swift
Created September 11, 2018 20:28
Clearing text and adding enter for an input UI field (UISearchBar e.g.), for UIViewController testing
extension XCUIElement {
func clearText() {
//
// cf. and tip courtesy of
// https://stackoverflow.com/questions/32821880/ui-test-deleting-text-in-text-field
//
guard let stringValue = self.value as? String else {
@pkuecuekyan
pkuecuekyan / Parser.swift
Created February 9, 2019 15:46
Parser — a readable and generic μ snippet for JSON/Codable parsing
//
// Parser
//
//
struct Parser<T: Decodable> {
static func parse(_ data: Data) -> T? {
var parsedPayload: T?
do {
parsedPayload = try JSONDecoder().decode(T.self, from: data)