Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

msaps/Listenable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

38d7184 Β· Mar 19, 2018
Jul 27, 2017
Jul 27, 2017
Mar 19, 2018
Feb 3, 2017
Jan 10, 2017
Nov 12, 2017
Jul 27, 2017
Jan 10, 2017
Mar 19, 2018
Jan 21, 2017
Jan 5, 2018

Repository files navigation

Listenable

Build Status Swift 4 CocoaPods Carthage compatible codecov GitHub release

Swift object that provides an observable platform for multiple listeners.

Requirements

  • iOS 9.0+
  • Xcode 9.x+
  • Swift 4

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(update: (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)

Listeners can also be updated exclusively relative to their priority:

	updateListeners(withPriority: ListenerPriority?, 
				    	  update: (listener: Listener, index: Int) -> Void)
					   
	updateListeners(withPriorities: ClosedRange<Int>?, 
				    	    update: (listener: Listener, index: Int) -> Void)

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.