Last active
August 29, 2015 14:24
-
-
Save joanmolinas/160ae6c8192812bf06b2 to your computer and use it in GitHub Desktop.
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
/* ClassCluster Example */ | |
/* Documentation: https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/ClassClusters/ClassClusters.html#//apple_ref/doc/uid/TP40010810-CH4 */ | |
/* This example explicated in Objc: http://stackoverflow.com/questions/1844158/what-exactly-is-a-so-called-class-cluster-in-objective-c */ | |
enum Types { | |
case Guffaw | |
case Giggle | |
} | |
protocol ClassClusterExample { | |
func ftw() -> String | |
} | |
class Laugh : ClassClusterExample { | |
func initWithType(type : Types) -> ClassClusterExample { | |
var c : ClassClusterExample! | |
switch type { | |
case .Guffaw: | |
c = Guffaw() | |
case .Giggle: | |
c = Giggle() | |
} | |
return c | |
} | |
func ftw() -> String { | |
return "Laugh" | |
} | |
} | |
class Guffaw : Laugh{ | |
override func ftw() -> String { | |
return "Guffaw" | |
} | |
} | |
class Giggle : Laugh { | |
override func ftw() -> String { | |
return "Giggle" | |
} | |
} | |
var guffaw = Laugh().initWithType(.Guffaw) | |
guffaw.ftw() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment