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
// swift-tools-version: 5.8 | |
// The swift-tools-version declares the minimum version of Swift required to build this package. | |
import PackageDescription | |
let package = Package( | |
name: "DictionaryCoded", | |
products: [ | |
// Products define the executables and libraries a package produces, making them visible to other packages. | |
.library( |
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 AttributeContainer { | |
init<S: AttributeScope>(_ keyPath: KeyPath<AttributeScopes, S.Type>, builder: (inout ScopedAttributeContainer<S>) -> Void) { | |
self.init() | |
builder(&self[dynamicMember: keyPath]) | |
} | |
static subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ((inout ScopedAttributeContainer<S>) -> Void) -> AttributeContainer where S: AttributeScope { | |
{ AttributeContainer(keyPath, builder: $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
import Foundation | |
extension DispatchWorkItem { | |
class func cancellable(_ work: @escaping (() -> Bool) -> Void) -> DispatchWorkItem { | |
class WeakBox<T: AnyObject> { | |
weak var value: T? | |
} | |
let box = WeakBox<DispatchWorkItem>() | |
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
@dynamicMemberLookup | |
struct Builder<Object> { | |
let object: Object | |
init(_ object: Object) { | |
self.object = object | |
} | |
subscript<T>(dynamicMember keyPath: WritableKeyPath<Object, T>) -> (T) -> Builder<Object> { | |
return { |
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 Encoder { | |
... | |
int32_t *_currentPosition; | |
... | |
} | |
Encoder::Encoder(int32_t *currentPosition, uint8_t ENCA, uint8_t ENCB) { | |
_ENCA = ENCA; |
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 | |
import Combine | |
extension Timer { | |
static func publish(at date: Date, tolerance: TimeInterval? = nil, on runLoop: RunLoop, in mode: RunLoop.Mode, options: RunLoop.SchedulerOptions? = nil) -> AnyPublisher<Date, Never> { | |
let subject = PassthroughSubject<Date, Never>() | |
let timer = Timer(fire: date, interval: 0, repeats: false) { _ in | |
subject.send(Date()) | |
subject.send(completion: .finished) |
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
@dynamicMemberLookup | |
struct Partial<Wrapped> { | |
private struct AnyProperty { | |
let keyPath: PartialKeyPath<Wrapped> | |
let value: Any | |
let writer: (inout Wrapped, Any) -> Void | |
init<T>(keyPath: WritableKeyPath<Wrapped, T>, value: T) { | |
self.keyPath = keyPath | |
self.value = 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
func sortedCount(of input: [String]) -> [(String, Int)] { | |
input.reduce(into: [String: (index: Int, count: Int)]()) { state, str in | |
var info = state[str] ?? (index: state.count, count: 0) | |
info.count += 1 | |
state[str] = info | |
}.sorted { lhs, rhs in | |
lhs.value.index < rhs.value.index | |
}.map { | |
($0.key, $0.value.count) | |
} |
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 CodingKeyRawValue: Hashable, Codable {} | |
extension String: CodingKeyRawValue {} | |
extension Int: CodingKeyRawValue {} | |
@propertyWrapper | |
struct CodableDictionary<Key: Hashable, Value> where Key: RawRepresentable, Key.RawValue: CodingKeyRawValue { | |
var wrappedValue: [Key: Value] | |
init(wrappedValue: [Key: Value]) { | |
self.wrappedValue = wrappedValue |
NewerOlder