This file contains hidden or 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
#! /usr/bin/swift | |
// Douglas Hill, March 2020 | |
// Prints out translations from Apple’s glossary files matching text in a supplied English .strings file. | |
// More detail in the article at https://douglashill.co/localisation-using-apples-glossaries/ | |
import Foundation | |
let stringsSource = URL(fileURLWithPath: "PUT THE PATH TO YOUR ENGLISH .strings FILE HERE") |
This file contains hidden or 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
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets. | |
// You can put this in the root view controller so the whole app will avoid the keyboard. | |
// Only tested on iOS 13.3. | |
// Made for https://douglashill.co/reading-app/ | |
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) { | |
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { | |
return | |
} | |
// Please consider whether the force unwrap here is safe for your own use case. |
This file contains hidden or 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
/// Performs a textual find and replace with the specified substitutions on all files in directory (recursive) that have the specified filename extensions. | |
func find(_ substitutions: [(find: String, replace: String)], allowedExtensions: Set<String>, directory rootURL: URL) { | |
let fileURLs = FileManager.default.enumerator(at: rootURL, includingPropertiesForKeys: nil)!.map { | |
$0 as! URL | |
} | |
.filter { | |
$0.hasDirectoryPath == false | |
} | |
.filter { | |
allowedExtensions.contains($0.pathExtension) |
This file contains hidden or 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, April 2017 | |
// From https://douglashill.co/reading-app/ | |
#if os(macOS) | |
import AppKit | |
public typealias Colour = NSColor | |
public typealias Font = NSFont | |
public typealias FontDescriptor = NSFontDescriptor | |
public typealias Image = NSImage |
This file contains hidden or 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 2019 | |
// Made for https://douglashill.co/reading-app/ | |
import Foundation | |
/// Tries really hard to read a string from a file. | |
/// | |
/// Brute forces encodings if necessary. This will only fail if the file can’t be interpreted | |
/// in any encoding, or if some other error occurs like not being able to read from the file. | |
/// |
This file contains hidden or 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, May 2019 | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A tab bar controller that allows navigating between tabs using cmd+number on a hardware keyboard. | |
/// So cmd+1 for the first tab, cmd+2 for the second tab etc. | |
public class KeyboardTabBarController: UITabBarController { | |
public override var keyCommands: [UIKeyCommand]? { |
This file contains hidden or 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, November 2019 | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`. | |
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end. | |
/// Limitations: | |
/// - Paging scroll views (isPagingEnabled = true) are not supported yet. | |
/// - The scroll view must become its own delegate so setting the delegate is not supported yet. |
This file contains hidden or 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
// A minimal iOS app set up entirely in code using Objective-C rather than using a storyboard and UIApplicationSceneManifest in the Info.plist. | |
// Last updated for iOS 18. | |
// Swift version: https://gist.github.com/douglashill/b8125f7e2336b6a47461df0d4898f64d | |
@import UIKit; | |
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate> | |
@end | |
@implementation SceneDelegate |
This file contains hidden or 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 UIKit | |
/// A wrapper view controller that makes the horizontal size class | |
/// be based on both the Dynamic Text size and the width available. | |
class AdaptiveTraitsContainer: UIViewController { | |
let wrappedViewController: UIViewController | |
init(wrappedViewController: UIViewController) { | |
self.wrappedViewController = wrappedViewController | |
super.init(nibName: nil, bundle: nil) |
This file contains hidden or 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 | |
// Made for https://douglashill.co/reading-app/ | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
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. |