🎧 Protocol driven object observation

Overview

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.

You might also like...
Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X

PINCache Fast, non-deadlocking parallel object cache for iOS and OS X. PINCache is a fork of TMCache re-architected to fix issues with deadlocking cau

👀 Observe deinit from outside of object

DeinitObserver Observe object's deinit from outside of object 🚀 Motivation I want to observe deinit of target object, but there are cases where I can

This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

Taking Pictures for 3D Object Capture

Taking Pictures for 3D Object Capture Capture high-quality images with depth and gravity data to use with RealityKit Object Capture. Overview Note: Th

A library to turn dictionary into object and vice versa for iOS. Designed for speed!

WAMapping Developed and Maintained by ipodishima Founder & CTO at Wasappli Inc. Sponsored by Wisembly A fast mapper from JSON to NSObject Fast Simple

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to load remote images

iOS NOW ⭐ This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to loa

Dogtector: dog breed detection app for iOS using YOLOv5 model combined with Metal based object decoder optimized
Dogtector: dog breed detection app for iOS using YOLOv5 model combined with Metal based object decoder optimized

Dogtector Project description Dogtector is dog breed detection app for iOS using YOLOv5 model combined with Metal based object decoder optimized for u

JSON object with Swift

JSON JSON using @dynamicMemberLookup, which allows us to write more natural code

A Stepper object that displays its value.
A Stepper object that displays its value.

ValueStepper Description ValueStepper is an improved replication of Apple's UIStepper object. The problem with UIStepper is that it doesn't display th

A declarative, thread safe, and reentrant way to define code that should only execute at most once over the lifetime of an object.

SwiftRunOnce SwiftRunOnce allows a developer to mark a block of logic as "one-time" code – code that will execute at most once over the lifetime of an

C-Xpress is a modern c-like object oriented programming language running on top of the .NET framework

C-Xpress Programming Language The cxpress programming language is a High Level object oriented programming language running on the .NET Framework C-Xp

Create or parse CoreData managed object model XMLs

MomXML Create or parse CoreData managed object model XMLs. Project description Model Contains struct objects which describe each XML elements. var mom

Framework for easily parsing your JSON data directly to Swift object.
Framework for easily parsing your JSON data directly to Swift object.

Server sends the all JSON data in black and white format i.e. its all strings & we make hard efforts to typecast them into their respective datatypes

Simple JSON Object mapping written in Swift

ObjectMapper ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

AppCodableStorage - Extends `@AppStorage` in SwiftUI to support any Codable object

AppCodableStorage Extends @AppStorage in SwiftUI to support any Codable object.

Annotation - Generate files to train with Object Detection by Create ML
Annotation - Generate files to train with Object Detection by Create ML

CreateML Annotation Generate files to train with Object Detection by Create ML.

A super fast & convenient object mapper tailored for your needs
A super fast & convenient object mapper tailored for your needs

A super fast & convenient object mapper tailored for your needs. Mapping objects to arrays or dictionaries can be a really cumbersome task, but those

Comments
  • Add prioritisation exclusive enumeration

    Add prioritisation exclusive enumeration

    • Add priorities ClosedRange<Int> parameter to updateListeners to allow for prioritisation exclusive updating.

    • Add convenience function updateListeners(withPriority: ) to allow for ListenerPriority values to be used for exclusive updating

    Resolves #10

    opened by msaps 1
Releases(2.2.0)
  • 2.2.0(Mar 19, 2018)

  • 2.1.0(Nov 12, 2017)

  • 2.0.0(Sep 12, 2017)

  • 2.0.0.beta.1(Jul 27, 2017)

  • 1.0.0(Mar 16, 2017)

  • 0.9.2(Jan 29, 2017)

    Added prioritised exclusive enumeration.

    Added

    • priorities parameter to updateListeners to allow for exclusive updating of a specified range of listener priorities. (#10)
    • Convenience function updateListeners(withPriority: ListenerPriority, ...) to Listenable. This allows for a specific ListenerPriority to be exclusively enumerated. (#10)
    • isListener(...) function to Listenable; returns a boolean as to whether an object is a registered listener. (#14)
    Source code(tar.gz)
    Source code(zip)
  • 0.9.1(Feb 4, 2017)

    Added listener prioritisation.

    Added

    • ListenerPriority to allow for enumeration priority to be set when adding listeners (#4)
    • Swift Package Manager support (#8)
    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(Jan 17, 2017)

Owner
Merrick Sapsford
Merrick Sapsford
A lightweight, event-driven architectural framework

Trellis Trellis features a declarative DSL that simplifies service bootstrapping: let cluster = try await Bootstrap { Group { Store(model:

Valentin Radu 25 Aug 16, 2022
MacOS Serial solution (Observable & Event-Driven) to make integration of Serial peripherals trivial

SerialSwift SerialSwift makes communicating with your Serial Peripherals on MacOS trivial. Better still, SerialSwift is designed to be fundamnetally O

Flowduino 2 Sep 9, 2022
URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.

URLEmbeddedView Features Simple interface for fetching Open Graph Data Be able to display Open Graph Data Automatically caching Open Graph Data Automa

Taiki Suzuki 643 Dec 20, 2022
A protocol that allows any class to be printed as if it were a struct or a JSON object.

ReflectedStringConvertible A protocol that extends CustomStringConvertible and uses reflection to add a detailed textual representation to any class.

Matt Comi 65 Dec 24, 2022
URLEmbeddedView automatically caches the object that is confirmed the Open Graph Protocol.

URLEmbeddedView Features Simple interface for fetching Open Graph Data Be able to display Open Graph Data Automatically caching Open Graph Data Automa

Taiki Suzuki 643 Dec 20, 2022
A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

There are many libraries out there that aims to help developers easily create and use SQLite databases. Unfortunately developers still have to get bogged down in simple tasks such as writing table definitions and SQL queries. SwiftyDB automatically handles everything you don't want to spend your time doing.

Øyvind Grimnes 489 Sep 9, 2022
Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling.

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling. Greatly inspired by Argo, but without a bizillion

Johannes Lund 1k Jul 15, 2022
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

Edwin Vermeer 964 Dec 14, 2022
CRUD is an object-relational mapping (ORM) system for Swift 4+.

CRUD is an object-relational mapping (ORM) system for Swift 4+. CRUD takes Swift 4 Codable types and maps them to SQL database tables. CRUD can create tables based on Codable types and perform inserts and updates of objects in those tables. CRUD can also perform selects and joins of tables, all in a type-safe manner.

PerfectlySoft Inc. 61 Nov 18, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022