MulticastDelegateKit 1.0.1

MulticastDelegateKit 1.0.1

Maintained by Alex Kisel.



  • By
  • Alex Kisel

Build Status Version License Platform

Multicast delegate framework written on Swift 4.2.

Features

Features
🎭 Adding multicast delegate to your custom classes
🚴 Subclasses of UIKit controls with multicast delegate property (currently only for UITableView)
🚀 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 responsableForSelectors() -> [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.