File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,14 @@ extension DestinationPlugin {
156156 timeline. remove ( plugin: plugin)
157157 }
158158
159+ public func find< T: Plugin > ( pluginType: T . Type ) -> T ? {
160+ return timeline. find ( pluginType: pluginType)
161+ }
162+
163+ public func findAll< T: Plugin > ( pluginType: T . Type ) -> [ T ] ? {
164+ return timeline. findAll ( pluginType: pluginType)
165+ }
166+
159167}
160168
161169extension Analytics {
@@ -212,6 +220,10 @@ extension Analytics {
212220 return timeline. find ( pluginType: pluginType)
213221 }
214222
223+ public func findAll< T: Plugin > ( pluginType: T . Type ) -> [ T ] ? {
224+ return timeline. findAll ( pluginType: pluginType)
225+ }
226+
215227 public func find( key: String ) -> DestinationPlugin ? {
216228 return timeline. find ( key: key)
217229 }
Original file line number Diff line number Diff line change @@ -136,6 +136,18 @@ extension Timeline {
136136 return found. first as? T
137137 }
138138
139+ internal func findAll< T: Plugin > ( pluginType: T . Type ) -> [ T ] ? {
140+ var found = [ Plugin] ( )
141+ for type in PluginType . allCases {
142+ if let mediator = plugins [ type] {
143+ found. append ( contentsOf: mediator. plugins. filter { ( plugin) -> Bool in
144+ return plugin is T
145+ } )
146+ }
147+ }
148+ return found as? [ T ]
149+ }
150+
139151 internal func find( key: String ) -> DestinationPlugin ? {
140152 var found = [ Plugin] ( )
141153 if let mediator = plugins [ . destination] {
Original file line number Diff line number Diff line change @@ -754,4 +754,29 @@ final class Analytics_Tests: XCTestCase {
754754 // it's running in sync mode.
755755 XCTAssertEqual ( analytics. pendingUploads!. count, 0 )
756756 }
757+
758+ func testFindAll( ) {
759+ let analytics = Analytics ( configuration: Configuration ( writeKey: " testFindAll " )
760+ . flushInterval ( 9999 )
761+ . flushAt ( 9999 )
762+ . operatingMode ( . synchronous) )
763+
764+ analytics. add ( plugin: ZiggyPlugin ( ) )
765+ analytics. add ( plugin: ZiggyPlugin ( ) )
766+ analytics. add ( plugin: ZiggyPlugin ( ) )
767+
768+ let myDestination = MyDestination ( )
769+ myDestination. add ( plugin: GooberPlugin ( ) )
770+ myDestination. add ( plugin: GooberPlugin ( ) )
771+
772+ analytics. add ( plugin: myDestination)
773+
774+ waitUntilStarted ( analytics: analytics)
775+
776+ let ziggysFound = analytics. findAll ( pluginType: ZiggyPlugin . self)
777+ let goobersFound = myDestination. findAll ( pluginType: GooberPlugin . self)
778+
779+ XCTAssertEqual ( ziggysFound!. count, 3 )
780+ XCTAssertEqual ( goobersFound!. count, 2 )
781+ }
757782}
You can’t perform that action at this time.
0 commit comments