Skip to content

Instantly share code, notes, and snippets.

@irace
Last active April 1, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irace/a06a9de2ffe10821e91936d763d3f6cf to your computer and use it in GitHub Desktop.
Save irace/a06a9de2ffe10821e91936d763d3f6cf to your computer and use it in GitHub Desktop.
Protocol inheritance and associated type specification
/*
This Swift bug seems to be related: https://bugs.swift.org/browse/SR-2235. Seems as though
the different ways that worked previously might have never actually been intended?
*/
protocol DataVendor {
associatedtype Vended
var data: [Vended]
func data(at index: Int) -> Vended
}
// This worked in Swift 3.0
protocol StringVendor: DataVendor {
typealias Vended = String
}
// This now seems to be required, as of Swift 3.1
protocol StringVendor: DataVendor {
var data: [String]
func data(at index: Int) -> String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment