Last active
December 1, 2016 15:40
-
-
Save dodikk/d5d62002c6cf730c4b059215beeb9203 to your computer and use it in GitHub Desktop.
protocol and associated type test
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
//: Playground - noun: a place where people can play | |
import UIKit | |
protocol A | |
{ | |
associatedtype SomeType | |
var a : SomeType { get } | |
} | |
protocol B : A | |
{ | |
typealias SomeType = String | |
var a : String { get } | |
} | |
class C | |
{ | |
// if uncommented, then it works. But we have a heavy dependency on `class AA` | |
// var ivar : AA? = nil | |
var ivar : B? = nil | |
} | |
class AA : A | |
{ | |
var a: String = "hello" | |
} | |
var aa = AA() | |
var cc = C() | |
cc.ivar = aa | |
if let cIvar = cc.ivar | |
{ | |
print(cIvar.a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AA
must be a sub-class ofA
since they belong to a third-party library in my case. And I can't change the hierarchy, I'm afraid.P.S. They are
Store
class andStore
protocol of the ReSwift library