Skip to content

Instantly share code, notes, and snippets.


Klemen Zagar klemenzagar91

View GitHub Profile
klemenzagar91 / MulticastDelegateV2.swift
Created Jun 22, 2017
Multicast Delegate with hash table
View MulticastDelegateV2.swift
class MulticastDelegate <T> {
private let delegates: NSHashTable<AnyObject> = NSHashTable.weakObjects()
func add(delegate: T) {
delegates.add(delegate as AnyObject)
func remove(delegate: T) {
for oneDelegate in delegates.allObjects.reversed() {
if oneDelegate === delegate as AnyObject {
klemenzagar91 / MulticastDelegate.swift
Last active Jun 22, 2017
Multicast Delegate Pattern for swift
View MulticastDelegate.swift
import Foundation
class MulticastDelegate <T> {
private var delegates = [WeakWrapper]()
func add(delegate: T) {
// If delegate is a class, add it to our weak reference array
delegates.append(WeakWrapper(value: delegate as AnyObject))
You can’t perform that action at this time.