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 {
156
156
timeline. remove ( plugin: plugin)
157
157
}
158
158
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
+
159
167
}
160
168
161
169
extension Analytics {
@@ -212,6 +220,10 @@ extension Analytics {
212
220
return timeline. find ( pluginType: pluginType)
213
221
}
214
222
223
+ public func findAll< T: Plugin > ( pluginType: T . Type ) -> [ T ] ? {
224
+ return timeline. findAll ( pluginType: pluginType)
225
+ }
226
+
215
227
public func find( key: String ) -> DestinationPlugin ? {
216
228
return timeline. find ( key: key)
217
229
}
Original file line number Diff line number Diff line change @@ -136,6 +136,18 @@ extension Timeline {
136
136
return found. first as? T
137
137
}
138
138
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
+
139
151
internal func find( key: String ) -> DestinationPlugin ? {
140
152
var found = [ Plugin] ( )
141
153
if let mediator = plugins [ . destination] {
Original file line number Diff line number Diff line change @@ -754,4 +754,29 @@ final class Analytics_Tests: XCTestCase {
754
754
// it's running in sync mode.
755
755
XCTAssertEqual ( analytics. pendingUploads!. count, 0 )
756
756
}
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
+ }
757
782
}
You can’t perform that action at this time.
0 commit comments