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
// A minimal iOS UIKit app set up entirely in code rather than using a storyboard and UIApplicationSceneManifest in the Info.plist. | |
// Last updated for iOS 18. | |
import UIKit | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
private var _window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let window = UIWindow(windowScene: scene as! UIWindowScene) |
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
// `@testable` needed to access `_data` | |
@testable import Markdown // This package: https://github.com/apple/swift-markdown | |
/// Writes a Markdown document to HTML. | |
/// | |
/// The primary goal is for output to match the output of Markdown.pl 1.0.1 as closely as possible. | |
/// <https://daringfireball.net/projects/markdown/> | |
/// | |
/// Usage: | |
/// |
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 URL { | |
/// Splits a URL that might have a fragment into the URL with the fragment removed and the fragment text. | |
/// | |
/// If there is no fragment in the URL, this will return a URL identical to the receiver and nil. | |
/// | |
/// Example input: https://github.com/douglashill/KeyboardKit/blob/main/Features.md#date-picker | |
/// Example output: (https://github.com/douglashill/KeyboardKit/blob/main/Features.md, date-picker) | |
func extractFragment() -> (urlWithoutFragment: URL, fragment: String?) { | |
guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else { | |
logError("Couldn’t create URL components from URL in order to extract fragment.") |
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
NSError *error = [NSError errorWithDomain:@"domain" code:123 userInfo:nil]; | |
[(NSFileHandle *)nil seekToOffset:0 error:&error]; | |
assert(error != nil); // 💥 Not OK. The error has gone! |
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 UIKit | |
class FourColumnsContainerViewController: UIViewController { | |
let outerSplitViewController = UISplitViewController(style: .tripleColumn) | |
let innerSplitViewController = UISplitViewController(style: .doubleColumn) | |
let primary = makeContentViewController("App") | |
let secondary = makeContentViewController("Files") | |
let mainContent = makeContentViewController("File Content") | |
let inspector = makeContentViewController("Inspector") |
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
/// A Swift property wrapper that implements ‘lazy let’. I.e. a read-only property that loads its value when first read. | |
/// Not safe for access from multiple threads. | |
/// Does not work the same as the lazy keyboard because the property initialiser will run before self is available. | |
/// Adapted from https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md | |
@propertyWrapper enum LazyLet<Value> { | |
case uninitialised(() -> Value) | |
case initialised(Value) | |
init(wrappedValue: @autoclosure @escaping () -> Value) { | |
self = .uninitialised(wrappedValue) |
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
#! /usr/bin/swift | |
// Douglas Hill, March 2020 | |
/* | |
Extracts the most common translations from Apple’s glossary files. | |
This script helped with localisation for KeyboardKit (https://github.com/douglashill/KeyboardKit) by leveraging Apple’s existing translations. | |
More detail in the article at https://douglashill.co/localisation-using-apples-glossaries/ |
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
#! /usr/bin/swift | |
// Douglas Hill, March 2020 | |
// This file is made available under the MIT license included at the bottom of this file. | |
/* | |
Extracts specific localised strings from Apple’s glossary files. | |
This script helped with localisation for KeyboardKit (https://github.com/douglashill/KeyboardKit) by leveraging Apple’s existing translations. |
NewerOlder