Created
June 3, 2016 16:27
-
-
Save mayoff/2fbd7f21f009226d55dd555d350a9c79 to your computer and use it in GitHub Desktop.
Attempting to make NSDateComponents conform to DictionaryLiteralConvertible
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
import Cocoa | |
public extension NSDateComponents { | |
public convenience init(_ components: DictionaryLiteral<NSCalendarUnit, Int>) { | |
self.init() | |
for (key, value) in components { | |
setValue(value, forComponent: key) | |
} | |
} | |
} | |
print(NSDateComponents([.Hour: 10, .Minute: 30])) | |
//extension NSDateComponents: DictionaryLiteralConvertible { | |
// public typealias Key = NSCalendarUnit | |
// public typealias Value = Int | |
// | |
// public convenience init(dictionaryLiteral elements: (NSDateComponents.Key, NSDateComponents.Value)...) { | |
// self.init() | |
// } | |
//} | |
// | |
// That extension fails: | |
// Initializer requirement 'init(dictionaryLiteral:)' can only be satisfied by a `required` initializer in the definition of non-final class 'NSDateComponents' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment