Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. protocol Foo {
  2. associatedtype F
  3. }
  4.  
  5. class FooClass : Foo {
  6. typealias F = String
  7. }
  8.  
  9. class Bar<F:Foo> {
  10. let foo: F
  11.  
  12. init(){
  13. // Error, cannot assign value of type 'FooClass' to type 'F'
  14. foo = FooClass()
  15. }
  16. }
  17.  
  18. func weird<F:Foo>(_ f: F){ }
  19.  
  20. func test(){
  21. weird(FooClass()) // this works
  22. }
  23.  
  24. class Bar<F:Foo> {
  25. let foo: FooClass.F
  26.  
  27. init(){
  28. foo = FooClass.F()
  29. }
  30. }
  31.  
  32. class Bar<F:Foo> {
  33. let foo: FooClass
  34.  
  35. init(){
  36. foo = FooClass()
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement