Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jayrhynas's full-sized avatar

Jayson Rhynas jayrhynas

View GitHub Profile
//
// UIButton+Deprecations.h
// Medly
//
// Created by Jayson Rhynas on 2023-03-02.
// Copyright © 2023 Medly Labs Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
// 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(
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) }
}
}
import Foundation
extension DispatchWorkItem {
class func cancellable(_ work: @escaping (() -> Bool) -> Void) -> DispatchWorkItem {
class WeakBox<T: AnyObject> {
weak var value: T?
}
let box = WeakBox<DispatchWorkItem>()
@dynamicMemberLookup
struct Builder<Object> {
let object: Object
init(_ object: Object) {
self.object = object
}
subscript<T>(dynamicMember keyPath: WritableKeyPath<Object, T>) -> (T) -> Builder<Object> {
return {
class Encoder {
...
int32_t *_currentPosition;
...
}
Encoder::Encoder(int32_t *currentPosition, uint8_t ENCA, uint8_t ENCB) {
_ENCA = ENCA;
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)
@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
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)
}
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