Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Last active June 28, 2017 18:45
Show Gist options
  • Save lukeredpath/7b3503a838444f5eaab38afbd61d6947 to your computer and use it in GitHub Desktop.
Save lukeredpath/7b3503a838444f5eaab38afbd61d6947 to your computer and use it in GitHub Desktop.
Swift typealias problem
protocol SomeProtocol {
typealias SomeType = String
}
class SomeClass: SomeProtocol {
let something: SomeType
}
// Compiles in Swift 3.1
// Compile error in Swift 3.0.2: "Use of undeclared type SomeType"
// The same problem exists with associated types:
protocol HasAssociatedType {
associatedtype CustomType
var something: CustomType { get }
}
class ImplementsAssociatedType: HasAssociatedType {
var something: String? // infers CustomType = String?
var somethingElse: CustomType { // Error: "Use of undeclared type CustomType"
return something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment