Skip to content

Instantly share code, notes, and snippets.

@dodikk
Last active December 1, 2016 15:40
Show Gist options
  • Select an option

  • Save dodikk/d5d62002c6cf730c4b059215beeb9203 to your computer and use it in GitHub Desktop.

Select an option

Save dodikk/d5d62002c6cf730c4b059215beeb9203 to your computer and use it in GitHub Desktop.
protocol and associated type test
//: 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)
}
@dodikk

dodikk commented Dec 1, 2016

Copy link
Copy Markdown
Author

class AA : B<String>

AA must be a sub-class of A 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 and Store protocol of the ReSwift library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment