Skip to content

Instantly share code, notes, and snippets.

@dcunited001
Created March 10, 2016 22:00
Show Gist options
  • Save dcunited001/05549bccc146924af537 to your computer and use it in GitHub Desktop.
Save dcunited001/05549bccc146924af537 to your computer and use it in GitHub Desktop.
Swift protocol questions
import Foundation
import Fuzi
import Swinject
// option one
// - fails because of "Self or associated type errors"
public protocol ParserNode {
typealias GenerateType
// parses xml nodes onto attributes defined on the ParserNode
func parseXML(nodes: Container, elem: XMLElement)
func generate(containers: [String: Container], options: [String: Any]) -> MDLType
// i'm getting errors here
func copy() -> ParserNode
}
// option two
// - it works, but I'm hesitant because of Generic-only constraints on ParserNode protocol
public protocol ParserNode2 {
typealias NodeType
typealias GenerateType
func parseXML(nodes: Container, elem: XMLElement)
func generate(containers: [String: Container], options: [String: Any]) -> MDLType
func copy() -> NodeType
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment