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 Foundation | |
| import Synchronization | |
| /// Synchronization mechanism to support cooperative and cancellable waiting on a value that _might_ become available _at some point in the future_. | |
| public final class UncertainFuture<Value: Sendable>: Sendable { | |
| /// Initializes a new uncertain future. | |
| public init() {} | |
| /// Return the passed value to all currently suspended callers waiting for ``value``. | |
| public func complete(_ value: Value) { |
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 Foundation | |
| import Synchronization | |
| class Thing { | |
| var value: Int = 0 | |
| var observers: [UUID: AsyncStream<Int>.Continuation] = [:] | |
| func nextValue() async throws -> Int { | |
| let id = UUID() | |
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 Synchronization | |
| func untilCancelled() async { | |
| print("1") | |
| let mutex: Mutex<CheckedContinuation<Void, Never>?> = .init(nil) | |
| await withTaskCancellationHandler { | |
| print("2") | |
| await withCheckedContinuation { continuation in | |
| print("3") |
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 task that is cancelled if goes out of scope, i.e. the last reference on it has been discarded. | |
| public final class ScopedTask<Success: Sendable, Failure: Error>: Sendable { | |
| /// The underlying task | |
| let wrapped: Task<Success, Failure> | |
| /// Wraps a task into a scoped task. | |
| init(wrapping task: Task<Success, Failure>) { | |
| wrapped = task | |
| } |
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
| extension UnsafeMutablePointer<UInt8> { | |
| /// Returns the index of the first element in the buffer that is not `0` | |
| func firstIndexNotZero(size bufferSize: Int) -> Int? { | |
| let stride = MemoryLayout<SIMD16<UInt8>>.stride | |
| let simdSize = bufferSize / stride | |
| // Iterate buffer using 16-component SIMD vectors | |
| let simdIndex: Int? = withMemoryRebound(to: SIMD16<UInt8>.self, capacity: simdSize) { buffer in | |
| let zero = SIMD16<UInt8>(repeating: 0) | |
| return (0..<simdSize).first { buffer[$0] != zero } |
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 SwiftUI | |
| struct ContentView: View { | |
| @State var width: Float = 0 | |
| @State var weight: Float = 0 | |
| var body: some View { | |
| VStack { | |
| HStack{ | |
| Text("Width") |
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 SwiftUI | |
| public final class SwiftUIView<Content: View>: UIView { | |
| private let hostingController: UIHostingController<Content> | |
| public init(rootView: Content) { | |
| hostingController = UIHostingController(rootView: rootView) | |
| super.init(frame: .zero) |
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 <Foundation/Foundation.h> | |
| #import <AppKit/AppKit.h> | |
| int main(int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| NSLog(@"languages: %@", [NSLocale.preferredLanguages componentsJoinedByString: @", "]); | |
| NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString: @"暗a"]; |
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
| // | |
| // UIViewController+Rotation.m | |
| // Ulysses | |
| // | |
| // Created by Götz Fabian on 12.10.17. | |
| // Copyright © 2017 Ulysses GmbH & Co. KG. All rights reserved. | |
| // | |
| #import "UIViewController+Rotation.h" |
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
| @implementation SwizzlingTextView /* Subclass of UITextView */ | |
| { | |
| BOOL _swizzled; | |
| } | |
| /* working solution */ | |
| - (void)setInputDelegate:(id<UITextInputDelegate>)inputDelegate | |
| { | |
| [super setInputDelegate: inputDelegate]; |
NewerOlder