Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Created August 3, 2015 01:00
Show Gist options
  • Save ttepasse/5fe8ee3a7fa765277faf to your computer and use it in GitHub Desktop.
Save ttepasse/5fe8ee3a7fa765277faf to your computer and use it in GitHub Desktop.
// This “solves“ http://inessential.com/2015/08/02/swift_diary_7_protocols_arrays_and_c
//
// But it turns into a small nightmare of generics, where every concrete class which
// conforms to NodeRepresentedObject has to be generic, because of those strange “Self
// or associated type requirements”. And that generics turn up a lot of more than one
// wants.
//
// The good part: One has to be explicit about ones requirements for the concrete children
// of a concrete node in Brents seemingly “outline-based” fictional mail client. Is that a good
// thing? Can an Email Message contain other nodes? Is that wanted?
// The bad part: One has to be explicit.
protocol NodeRepresentedObject : class {
typealias Children = NodeRepresentedObject
var children: [Children]? {get}
}
protocol EmailMessage : NodeRepresentedObject {
// stuff here…
}
class Mailbox<T : EmailMessage> : NodeRepresentedObject {
var messages = [T]()
var children: [T]? {
get {
return messages
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment