Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/Segment/Plugins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ extension Analytics {
public func find<T: Plugin>(pluginType: T.Type) -> T? {
return timeline.find(pluginType: pluginType)
}

public func find(key: String) -> DestinationPlugin? {
return timeline.find(key: key)
}
}
11 changes: 11 additions & 0 deletions Sources/Segment/Timeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ extension Timeline {
}
return found.first as? T
}

internal func find(key: String) -> DestinationPlugin? {
var found = [Plugin]()
if let mediator = plugins[.destination] {
found.append(contentsOf: mediator.plugins.filter{ plugin in
guard let p = plugin as? DestinationPlugin else { return false }
return p.key == key
})
}
return found.first as? DestinationPlugin
}
}

// MARK: - Plugin Timeline Execution
Expand Down
4 changes: 4 additions & 0 deletions Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ final class Analytics_Tests: XCTestCase {

analytics.track(name: "testDestinationEnabled")

let dest = analytics.find(key: myDestination.key)
XCTAssertNotNil(dest)
XCTAssertTrue(dest is MyDestination)

wait(for: [expectation], timeout: 1.0)
}

Expand Down