Generics
Generics
Code
func genericTrack<T>(_ type: AVMediaCharacteristic) async throws -> T? {
switch type {
case .audible:
let selectedOption = try await getCurrentAVMediaSelectionOptions(.audible)
return ATrack(id: selectedOption.displayName,
language: selectedOption.locale) as? T
case .legible:
let selectedOption = try await getCurrentAVMediaSelectionOptions(.legible)
return BTrack(id: selectedOption.displayName,
language: selectedOption.locale) as? T
default:
print("Error")
}
return nil
}
References
Generics Medium
Apple docs
Generics Basics