This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Contacts | |
import Intents | |
protocol ContactStoring { | |
func enumerateContacts(with fetchRequest: CNContactFetchRequest, usingBlock block: @escaping (CNContact, UnsafeMutablePointer<ObjCBool>) -> Void) throws | |
} | |
extension CNContactStore: ContactStoring {} | |
class IntentPersonProvider { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Contacts | |
import Intents | |
class IntentHandler: INExtension, INStartCallIntentHandling { | |
/// CNContactsStore implementation to get a person from contacts. | |
/// | |
/// See https://gist.github.com/quintonpryce/d69499bf40bdef208bd35d00aba188db | |
lazy var personProvider = IntentPersonProvider() | |
@available(iOSApplicationExtension 13.0, *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
subscript(index: Int) -> Character { | |
return self[self.index(self.startIndex, offsetBy: index)] | |
} | |
} | |
extension String { | |
public func levenshtein(_ other: String) -> Int { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Analytics: AnalyticsScope { | |
public static let shared: AnalyticsScope = Analytics() | |
private var eventTrackers: [EventTrackerKey: EventTracker] = [:] | |
private let failureHandler: FailureHandler | |
public init() { | |
failureHandler = SimpleFailureHandler() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol AnalyticsScope { | |
func track(event: AnalyticsEvent) | |
func track<T: AnalyticsParameter>(event: AnalyticsEvent, with parameters: T) | |
func addEventTracker(key: EventTrackerKey, tracker: EventTracker) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func trackAnalytic<T: AnalyticsParameter>(event: AnalyticsEvent, parameters: T?) { | |
if event.supportedTrackers.isEmpty { | |
failureHandler.failure("Event \(event.name) does not have any supported EventTrackers.") | |
return | |
} | |
for trackerKey in event.supportedTrackers { | |
if let eventTracker = eventTrackers[trackerKey] { | |
if eventTracker.isEventNameSupported(event: event.name) { | |
if let parameters = parameters, !parameters.isEmpty() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func trackAnalytic<T: AnalyticsParameter>(event: AnalyticsEvent, parameters: T?) { | |
if event.supportedTrackers.isEmpty { | |
failureHandler.failure("Event \(event.name) does not have any supported EventTrackers.") | |
return | |
} | |
for trackerKey in event.supportedTrackers { | |
if let eventTracker = eventTrackers[trackerKey] { | |
if let parameters = parameters, !parameters.isEmpty() { | |
eventTracker.track(event: event.name, with: parameters) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let failureHandler: FailureHandler | |
public init() { | |
failureHandler = SimpleFailureHandler() | |
} | |
public init(failureHandler: FailureHandler) { | |
self.failureHandler = failureHandler | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol FailureHandler { | |
func failure(_ message: String) | |
} | |
class SimpleFailureHandler: FailureHandler { | |
func failure(_ message: String) { | |
assertionFailure(message) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmptyParameter: AnalyticsParameter { | |
var parameter: Bool? | |
typealias ParameterType = Bool? | |
init() { | |
parameter = nil | |
} | |
} |
NewerOlder