Last active
October 28, 2015 13:46
-
-
Save diegosanchezr/7b2e784fce8da35d22a2 to your computer and use it in GitHub Desktop.
Protocol conformance in collections
This file contains 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
import Foundation | |
protocol UniqueIdentificableProtocol { | |
var uid: String { get } | |
} | |
protocol UniqueIdentificableSubtypeProtocol: UniqueIdentificableProtocol { | |
var c: String { get } | |
} | |
class UniqueIdentificableClass { | |
var uid: String { return "uid" } | |
} | |
class UniqueIdentificableSubtypeClass: UniqueIdentificableClass { | |
var c: String { return "c"} | |
} | |
let myCollectionClasses: [UniqueIdentificableSubtypeClass] = [UniqueIdentificableSubtypeClass]() | |
let myCastedCollectionClasses: [UniqueIdentificableClass] = myCollectionClasses // Everything ok with classes | |
let myCollectionProtocols = [UniqueIdentificableSubtypeProtocol]() | |
let myCastedCollectionProtocols: [UniqueIdentificableProtocol] = myCollectionProtocols // Compiler error | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment