Skip to content

Instantly share code, notes, and snippets.

View kiarashvosough1999's full-sized avatar
🍉

Kiarash Vosough kiarashvosough1999

🍉
View GitHub Profile
protocol CancelableTask: Sendable {
var hashValue: Int { get }
func cancel()
}
extension Task: CancelableTask {}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
let hashTable = NSHashTable<NSMutableData>(options: .copyIn)
var str: NSMutableData? = NSMutableData.init()
hashTable.add(str)
str = nil
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
let hashTable = NSHashTable<NSString>.weakObjects()
var str: NSMutableString? = NSMutableString.init(string: "dasdasdas")
hashTable.add(str)
str = nil
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
@kiarashvosough1999
kiarashvosough1999 / Test++Count++NSHashTable.swift
Created September 7, 2022 21:43
Test++Count++NSHashTable
class Test: NSObject {
deinit {
print("deinit")
}
}
let tests = NSHashTable<Test>.weakObjects()
var test: Test? = Test()
tests.add(test)
final class Test {
deinit {
print("Deinited")
}
}
let hashTable: NSHashTable<Test> = .weakObjects()
var optionalInstance: Test? = Test()
import UIKit
import Combine
protocol UIControlPublishable: UIControl {}
extension UIControlPublishable {
func publisher(for event: UIControl.Event) -> UIControl.InteractionPublisher<Self> {
return InteractionPublisher(control: self, event: event)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher where Self.Failure == Never {
func assign(to failablePublished: CurrentValuePublished<Self.Output,Self.Failure>) -> AnyCancellable {
self.assign(to: \.wrappedValue, on: failablePublished)
}
}
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
import Foundation
infix operator ->>: DefaultPrecedence
public protocol Castable {
func forceCast<U>(to type: U.Type) -> U
func AS<U>(to type: U.Type) -> U?
import Combine
import CoreData
import Foundation
class CDPublisher<Entity>: NSObject, NSFetchedResultsControllerDelegate, Publisher where Entity: NSManagedObject {
typealias Output = [Entity]
typealias Failure = Error
private let request: NSFetchRequest<Entity>
private let context: NSManagedObjectContext