Skip to content

Commit

Permalink
added two early exists to safeValue(forField:in:), one if the string …
Browse files Browse the repository at this point in the history
…is empty and one where it's a single key (instead of a keypath
  • Loading branch information
Blair McArthur committed Nov 7, 2016
1 parent bd919d3 commit c8c9c3b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions KeyedMapper/Objects/KeyedMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public struct KeyedMapper<Object: Mappable> {
}

internal func safeValue(forField field: Object.Key, in dictionary: NSDictionary) -> Any? {
guard !field.stringValue.isEmpty else {
return dictionary
}

guard field.stringValue.contains(".") else {
return dictionary[field.stringValue]
}

var object: Any? = dictionary
var keys = field.stringValue.characters.split(separator: ".").map(String.init)

Expand Down

0 comments on commit c8c9c3b

Please sign in to comment.