Created
October 1, 2015 17:55
-
-
Save owensd/44c02f1b4f9130508e4b to your computer and use it in GitHub Desktop.
Need some help
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
enum Error : ErrorType { | |
case NIY | |
} | |
protocol LangValue { | |
mutating func set(object object: LangValue, forKey key: String) throws | |
} | |
extension Int : LangValue {} | |
extension LangValue { | |
mutating func set(object object: LangValue, forKey key: String) throws { throw Error.NIY } | |
} | |
extension Dictionary : LangValue {} | |
//extension Dictionary { | |
// mutating func set(object object: Value, forKey key: Key) throws { | |
// //self[key] = object | |
// } | |
//} | |
protocol StringType : Hashable { | |
var characters: String.CharacterView { get } | |
} | |
extension String : StringType {} | |
extension Dictionary where Key : StringType, Value : LangValue { | |
mutating func set(object object: Value, forKey key: Key) throws { | |
self[key] = object | |
} | |
} | |
var dict = Dictionary<String, LangValue>() | |
do { try dict.set(object: 12, forKey: "Why?") } catch { print("\(error)") } | |
// QUESTION: Why is the LangValue.set(object,forKey) version called instead of | |
// the Dictionary.set(object,forKey) version called? String is a StringType and | |
// LangValue is a LangValue. Shouldn't that be the right one called? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment