Support NSDate with custom mapped function
chriscombs opened this issue · comments
Currently has a Date
class, but would be nice to support NSDate
natively.
After investigating, we'll need a separate mapped function for it
This has been added by @chriscombs and @jakobmygind
It's missing documentation though...
Didn’t Chris add it?
Kasper Welner
iOS Lead
Nodes - We build awesome digital stuff
Mobile: +45 41 62 60 20
Web: http://www.nodes.dk http://www.nodes.dk/
On 15 Mar 2016, at 21:43, Dominik Hádl notifications@github.com wrote:
It's missing documentation though...
—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub #17 (comment)
I don't see any in the source. Also, there's some things that make the generics in the code useless.
The new mapped
function overload looks like this:
public func mapped<T: HexInitializable>(dictionary: NSDictionary?, key: String) -> T? {
guard let dict = dictionary else {
return nil
}
let sourceOpt = dict[key]
if let source = sourceOpt as? String where source.isEmpty == false {
return UIColor.colorWithHexString(source) as? T
}
return nil
}
It expects an object which adheres to HexInitializable
but then returns plain UIColor.colorWithHexString
, instead of properly using that protocol to instantiate a generic object. There were also some formatting issues, I'll submit a PR in a few seconds for this.
Nice thx!
Kasper Welner
iOS Lead
Nodes - We build awesome digital stuff
Mobile: +45 41 62 60 20
Web: http://www.nodes.dk http://www.nodes.dk/
On 15 Mar 2016, at 21:48, Dominik Hádl notifications@github.com wrote:
I don't see any in the source. Also, there's some things that make the generics in the code useless.
The new mapped function overload looks like this:
public func mapped<T: HexInitializable>(dictionary: NSDictionary?, key: String) -> T? {
guard let dict = dictionary else {
return nil
}let sourceOpt = dict[key] if let source = sourceOpt as? String where source.isEmpty == false { return UIColor.colorWithHexString(source) as? T } return nil }
It expects an object which adheres to HexInitializable but then returns plain UIColor.colorWithHexString, instead of properly using that protocol to instantiate a generic object. There were also some formatting issues, I'll submit a PR in a few seconds for this.
—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub #17 (comment)
Wtf.. Apparently, I'm tired. I was looking and talking about custom mapped overload for UIColor
. There is no overload for NSDate
so far.
Just started on this, I will create a PR with support for NSDate
with no need for wrapper object tomorrow morning.