Standard escape codes are prefixed with Escape:
- Ctrl-Key:
^[ - Octal:
\033 - Unicode:
\u001b - Hexadecimal:
\x1B - Decimal:
27
| // | |
| // A Swift property wrapper for adding "indirect" to struct properties. | |
| // Enum supports this out of the box, but for some reason struct doesn't. | |
| // | |
| // This is useful when you want to do something recursive with structs like: | |
| // | |
| // struct Node { | |
| // var next: Node? | |
| // } | |
| // |
| /// Wait for async operation to return value and call callback with the value | |
| /// This class is intended to workaround/simplify async/await + actors isolation | |
| /// https://twitter.com/krzyzanowskim/status/1523233140914876416 | |
| private class AsyncWaiter<T> { | |
| var didReceiveValue: Bool = false | |
| let value: (T) -> Void | |
| let operation: () async throws -> T | |
| init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) { | |
| self.value = value |
| // | |
| // Created by Frank Gregor on 19.04.22. | |
| // | |
| import SwiftUI | |
| public struct Platform: OptionSet { | |
| public var rawValue: UInt8 | |
| public static let iOS: Platform = Platform(rawValue: 1 << 0) |
| // Excerpt from https://github.com/krzyzanowskim/CoreTextWorkshop | |
| // Licence BSD-2 clause | |
| // Marcin Krzyzanowski [email protected] | |
| func getSizeThatFits(_ attributedString: NSAttributedString, maxWidth: CGFloat) -> CGSize { | |
| let framesetter = CTFramesetterCreateWithAttributedString(attributedString) | |
| let rectPath = CGRect(origin: .zero, size: CGSize(width: maxWidth, height: 50000)) | |
| let ctFrame = CTFramesetterCreateFrame(framesetter, CFRange(), CGPath(rect: rectPath, transform: nil), nil) |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| Task { | |
| // 1️⃣❓ UIViewController is in a MainActor context, so this Task | |
| // will inherit that, so the following pretend expensive call will | |
| // be on the main thread and likely block? | |
| ExpensiveOperationPerformer.doExpensiveLoopAndPrint() | |
| } |
Author: https://www.cyanhall.com/
Core Animation's original name is Layer Kit
Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.
In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.
There are four hierarchies, each performing a different role:
| // | |
| // TaggerView.swift | |
| // | |
| // Created by Alex Hay on 21/11/2020. | |
| // | |
| // Simple interface for adding tags to an array in SwiftUI | |
| // Example video: https://imgur.com/gallery/CcA1IXp | |
| // alignmentGuide code from Asperi @ https://stackoverflow.com/a/58876712/11685049 | |
| import SwiftUI |
| import SwiftUI | |
| struct ColorText: View { | |
| // MARK:- Properties | |
| /// The attributed string to display. | |
| private let attributedString: AttributedString | |
| var body: some View { |
| import UIKit | |
| struct IceCream { | |
| let title: String | |
| let icon: UIImage | |
| } | |
| struct AppSettings { | |
| static var fontSize = 17.0 | |
| } |