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
@available(iOS 16.0, macOS 13.0, watchOS 9.0, *) | |
@propertyWrapper | |
public struct AsyncPublished<Value> { | |
@available(*, unavailable, message: "@AsyncPublished is only available on properties of classes") | |
public var wrappedValue: Value { | |
get { fatalError() } | |
set { fatalError() } // swiftlint:disable:this unused_setter_value | |
} | |
public let projectedValue: AsyncStream<Value> | |
public init(initialValue: Value) { |
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 Foundation | |
/* | |
Somewhere in Foundation | |
public protocol Foo { | |
... | |
public init<T>?(foo value: T) where T: Foo | |
... | |
} |
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
protocol Example { | |
associatedtype Value | |
func value() -> Value | |
} | |
struct AnyExample<Value> { | |
private class Container<Value> { | |
func value() -> Value { | |
fatalError() | |
} |
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
@propertyWrapper | |
struct ErasedToAnyPublisher<Upstream: Publisher> { | |
var wrappedValue: AnyPublisher<Upstream.Output, Upstream.Failure> { | |
upstream.eraseToAnyPublisher() | |
} | |
let upstream: Upstream | |
init(upstream: Upstream) { | |
self.upstream = upstream | |
} | |
} |
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
public extension Publisher { | |
/// Assigns each element from a Publisher to a property on an object. | |
/// | |
/// - Parameters: | |
/// - keyPath: The key path of the property to assign. | |
/// - object: The object on which to assign the value. | |
/// - Returns: A cancellable instance; used when you end assignment of the received value. Deallocation of the result will tear down the subscription stream. | |
func assignResult<Root>(to keyPath: ReferenceWritableKeyPath<Root, Result<Self.Output, Self.Failure>>, | |
on object: Root) -> AnyCancellable { | |
sink(receiveCompletion: { completion in |
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
class Foo { | |
var body: some View { | |
... | |
} | |
} | |
class Bar: Foo { | |
override var body: some View { | |
... | |
} |
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
// | |
// BoundedQueue.swift | |
// | |
// Copyright © 2017 Doug Russell. All rights reserved. | |
// | |
import Foundation | |
public class BoundedQueue { | |
private let group = DispatchGroup() |
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 <Foundation/Foundation.h> | |
#include <objc/message.h> | |
typedef void (*DISPATCH_IMP_NOARGS_NORETURN)(id, SEL); | |
typedef id (*DISPATCH_IMP_NOARGS)(id, SEL); | |
@interface Foo : NSObject | |
@end |
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
#if !defined(NS_BLOCK_ASSERTIONS) | |
#define RSTLSetOfStringsAssert(set) [set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { NSParameterAssert([obj isKindOfClass:[NSString class]]); }]; | |
#else | |
#define RSTLSetOfStringsAssert(set) | |
#endif |
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
#pragma mark - Memory Cache Subscripting | |
// Allow self[key] for looking up and writing to memory cache | |
// This is mostly a novelty | |
- (id)objectForKeyedSubscript:(id)key | |
{ | |
return [self.memoryCache objectForKey:key]; | |
} |
NewerOlder