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
// TaskMeeting | |
// (c) 2022, Nikolai Ruhe | |
/// A type that synchronizes progress of two tasks. | |
public final actor TaskMeeting: Sendable { | |
private var completion: CheckedContinuation<Void, Error>? = nil | |
/// This method synchronizes two tasks so that both perform the closure at | |
/// the same time. Both tasks need to call `rendezvous`. | |
/// |
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 Dispatch | |
@globalActor | |
final actor MyMainActor { | |
// Donβt allow others to create instances | |
private init() {} | |
// Requirements from the implicit GlobalActor conformance | |
typealias ActorType = MyMainActor |
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 SwiftUI | |
extension View { | |
public func discover<T: UIView>( | |
where predicate: @escaping (T) -> Bool = { _ in true }, | |
_ closure: @escaping (T) -> Void | |
) -> some View { | |
overlay( | |
DiscoveryView(predicate: predicate, setup: closure) | |
.frame(width: 0, height: 0) |
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
#!/bin/zsh | |
cd "$(dirname "$0")/.." | |
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then | |
FAIL_ON_ERRORS=true | |
echo "Running in --fail-on-errors mode" | |
ERROR_START="" | |
COLOR_END="" | |
INFO_START="" |
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
struct Contact: Decodable, CustomStringConvertible { | |
var id: String | |
@NestedKey | |
var firstname: String | |
@NestedKey | |
var lastname: String | |
@NestedKey | |
var address: String | |
enum CodingKeys: String, NestableCodingKey { |
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
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched. | |
public struct UIKitTabView: View { | |
private var viewControllers: [UIHostingController<AnyView>] | |
private var selectedIndex: Binding<Int>? | |
@State private var fallbackSelectedIndex: Int = 0 | |
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) { | |
self.viewControllers = views().map { | |
let host = UIHostingController(rootView: $0.view) | |
host.tabBarItem = $0.barItem |
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
/// Log the current filename and function, with an optional extra message. Call this with no arguments to simply print the current file and function. Log messages will include an Emoji selected from a list in the function, based on the hash of the filename, to make it easier to see which file a message comes from. | |
/// - Parameter message: Optional message to include | |
/// - file: Don't use; Swift will fill in the file name | |
/// - function: Don't use, Swift will fill in the function name | |
/// - line: Don't use, Swift will fill in the line number | |
func logMilestone(_ message: String? = nil, file: String = #file, function: String = #function, line: Int = #line) -> Void { | |
#if DEBUG | |
// Feel free to change the list of Emojis, but don't make it shorter, because a longer list is better. | |
let logEmojis = ["π","π","π±","π","πΊ","π½","πΎ","π€","π","π","π","π§ ","π","π§€","πΆ","π±","π","πΉ","π¦","π»","π¨","π΅","π¦","π¦","π","π₯","π₯","βοΈ","π","π₯","π½","π","πΏ","πΉ","π","β€οΈ","π§‘","π","π","π","π","π"] | |
let logEmoji = logEmojis[abs( |
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
- (UIImage *)dynamicImage | |
{ | |
UITraitCollection *const baseTraitCollection = /* an existing trait collection */; | |
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]]; | |
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]; | |
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]]; | |
__block UIImage *lightImage; | |
[lightTraitCollection performAsCurrentTraitCollection:^{ | |
lightImage = /* draw image */; |
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
/// Conforming to this protocol allows for URL handling | |
protocol URLHandler { | |
/// Handle a URL | |
/// | |
/// - Parameter url: The propagated url | |
/// - Returns: The handled status | |
func handleURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler completion: ((Bool) -> Void)?) | |
} | |
// MARK: - Error Propagation |
NewerOlder