Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayoff/2fbd7f21f009226d55dd555d350a9c79 to your computer and use it in GitHub Desktop.
Save mayoff/2fbd7f21f009226d55dd555d350a9c79 to your computer and use it in GitHub Desktop.
Attempting to make NSDateComponents conform to DictionaryLiteralConvertible
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