Last active
October 14, 2017 08:35
-
-
Save ilyapuchka/6ef4a708fb438c35e66b165130b1f20e to your computer and use it in GitHub Desktop.
Generic typealias in protocol
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
/* | |
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