Latest | 1.0.1 |
---|---|
Homepage | https://github.com/elano50/MulticastDelegateKit |
License | MIT |
Platforms | ios 10.0 |
Authors |
Multicast delegate framework written on Swift 4.2.
Features
Features | |
---|---|
:performing_arts: | Adding multicast delegate to your custom classes |
:bicyclist: | Subclasses of UIKit controls with multicast delegate property (currently only for UITableView) |
:rocket: | Manage which delegates responsible for returning value for UIKit controls using responsibleForSelectors() function |
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
UITableView example
let tableView = MultidelegateTableView()
tableView.multiDelegate.add(delegate: self)
Custom class example
protocol FooClassDelegate {
func fooEvent()
}
class FooClass {
var multicastDelegate = MulticastDelegate<FooClassDelegate>()
func foo() {
multicastDelegate.invoke { delegate in
delegate.fooEvent()
}
}
}
class BarClass: FooClassDelegate {
var foo = FooClass()
var baz = BazClass()
init() {
foo.multicastDelegate.add(delegate: self)
foo.multicastDelegate.add(delegate: baz)
}
func fooEvent() {
}
}
class BazClass: FooClassDelegate {
func fooEvent() {
}
}
Responsible for selectors example
Some delegate methods can return a value. So when we have several delegates, we need a mechanism to manage which delegate is responsible for returning value. Only one delegate should be responsible for returning value, other delegates are listeners.
class FooClass: UITableViewDelegate, MulticastableDelegate {
var tableView: MultidelegateTableView
func setup() {
tableView.multiDelegate.add(delegate: self)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func responsibleForSelectors() -> [String]? {
return [#selector(tableView(_:heightForRowAt:)).description]
}
}
Requirements
iOS 10.0+
Swift 4.0+
Installation
MulticastDelegate is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'MulticastDelegateKit'
Author
Alex Kisel, [email protected]
License
MulticastDelegate is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "MulticastDelegateKit", "version": "1.0.1", "summary": "A library which allows to have several delegates instead of one", "description": "A simple library which allows to have several delegates instead of one. Also it includes subclasses for UIKit controls to work with MulticastDelegateKit.", "homepage": "https://github.com/elano50/MulticastDelegateKit", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Alex Kisel": "[email protected]" }, "source": { "git": "https://github.com/elano50/MulticastDelegateKit.git", "tag": "1.0.1" }, "platforms": { "ios": "10.0" }, "source_files": "MulticastDelegate/Classes/**/*" }
Tue, 18 Dec 2018 11:28:04 +0000