Skip to content

Instantly share code, notes, and snippets.

@ilyapuchka
Last active October 14, 2017 08:35
Show Gist options
  • Save ilyapuchka/6ef4a708fb438c35e66b165130b1f20e to your computer and use it in GitHub Desktop.
Save ilyapuchka/6ef4a708fb438c35e66b165130b1f20e to your computer and use it in GitHub Desktop.
Generic typealias in protocol
/*
Xcode 8 beta 6
Apple Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38)
Target: x86_64-apple-macosx10.9
*/
struct Generic<A, B> {}
//if typealias is defined inside the concrete type it works:
class SomeClass {
typealias Alias<A> = Generic<A, SomeClass>
let int: Alias<Int>
init(int: Alias<Int>) {
self.int = int
}
}
//but it does not work from inside protocol
protocol AliasProtocol {
typealias Alias<A> = Generic<A, Self>
}
class SomeClass: AliasProtocol {
let int: Alias<Int> //does not compile - "Use of unresolved identifier 'Alias'. Did you mean 'Alias'?"
let int: SomeClass.Alias<Int> //crashes compiler
init(int: SomeClass.Alias<Int>) {
self.int = int
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment