Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Latest commit

 

History

History
19 lines (14 loc) · 489 Bytes

README.md

File metadata and controls

19 lines (14 loc) · 489 Bytes

Observable-Swift-Protocol

Mainly used in situation when you need to hold many delegates (without strong references) and call some method for each.

protocol PlayerObserver: AnyObject  {
	func someMethod()
}

class Player: NSObject, Observable, AVAudioPlayerDelegate {
	typealias ObserverType = PlayerObserver // protocol

	var observers: [() -> PlayerObserver?] = []

	func somethigChanged() {
		send { $0.someMethod() }  // call someMethot on all available observers
	}
}