-
-
Save thekarladam/c3094769cc8c87bf55e3 to your computer and use it in GitHub Desktop.
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
func admitFromNode<T : NodeDerivable>(node: Node) -> T? { | |
return T.fromNode(node) | |
} | |
protocol NodeDerivable { | |
static func fromNode(node: Node) -> Self? | |
} | |
extension Int : NodeDerivable { | |
static func fromNode(node: Node) -> Int? { | |
return Int(node.text) | |
} | |
} | |
extension Double : NodeDerivable { | |
static func fromNode(node: Node) -> Double? { | |
return Double(node.text) | |
} | |
} | |
extension String : NodeDerivable { | |
static func fromNode(node: Node) -> String? { | |
return String(node.text) | |
} | |
} | |
extension NSURL : NodeDerivable { | |
static func fromNode(node: Node) -> NSURL? { //error: method 'fromNode' in non-final class 'NSURL' must return `Self` to conform to protocol 'NodeDerivable' | |
//static func fromNode(node: Node) -> Self? { //error: cannot convert return expression of type 'NSURL?' to return type 'Self?' | |
return NSURL(string: node.text) | |
} | |
} |
Author
thekarladam
commented
Nov 17, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment