muescha / Listenable

Observable pattern in Swift made easy

Home Page:http://sapsford.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listenable

Build Status CocoaPods codecov

Swift object that provides an observable platform for multiple listeners.

Installation

Listenable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Listenable'

And run pod install.

Usage

Create a Listenable object either by inheriting or initializing a Listenable typed with a protocol:

class ListenableObject: Listenable<ListenableDelegate> {
  // Class
}

You can then add and remove listeners, and update them as required...

Add Listener(s):

add(listener: Listener, priority: ListenerPriority) -> Bool
add(listeners: [Listener], priority: ListenerPriority) -> Void

Remove Listener(s):

remove(listener: Listener) -> Bool
remove(listeners: [Listener]) -> Void
removeAllListeners()

Enumerate & Update Listeners:

updateListeners(updateBlock: (listener: Listener, index: Int) -> Void)

Prioritisation

ListenerPriority allows for definition of enumeration priority for a listener; by default the priority parameter is set to .low. The following values can be assigned:

.low 		(Raw: 0)
.high 		(Raw: 1000)
.custom		(Valid range: 0-1000)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/MerrickSapsford/Listenable.

License

The library is available as open source under the terms of the MIT License.

About

Observable pattern in Swift made easy

http://sapsford.tech

License:MIT License


Languages

Language:Swift 94.1%Language:Ruby 3.3%Language:Objective-C 2.3%Language:Shell 0.3%