Created
March 1, 2015 12:10
-
-
Save kumabook/c84bcbbad1c44675e74a to your computer and use it in GitHub Desktop.
Protocol 'ObserverProtocol' can only be used as a generic constraint because it has Self or associated type requirements
This file contains hidden or 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 ObserverProtocol: Equatable { | |
func notified() | |
} | |
class Observable: NSObject { | |
var observers: [ObserverProtocol] = [] | |
override init() { | |
super.init() | |
} | |
func addObserver(observer: ObserverProtocol) { | |
observers.append(observer) | |
} | |
func removeObserver(observer: ObserverProtocol) { | |
if let index = find(observers, observer) { | |
observers.removeAtIndex(index) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment