Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

- Fix same property name on keyPath: #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Sources/Unboxer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,24 @@ private extension Unboxer {
case .keyPath(let keyPath):
var node: UnboxPathNode = self.dictionary
let components = keyPath.components(separatedBy: ".")
let lastKey = components.last

for key in components {
guard let nextValue = node.unboxPathValue(forKey: key) else {
throw UnboxPathError.missingKey(key)
let endPath = components.count - 1
for i in 0..<components.count{
guard let nextValue = node.unboxPathValue(forKey: components[i]) else {
throw UnboxPathError.missingKey(components[i])
}

if key == lastKey {
return try transform(nextValue).orThrow(UnboxPathError.invalidValue(nextValue, key))
if i == endPath {
return try transform(nextValue).orThrow(UnboxPathError.invalidValue(nextValue, components[i]))
}

guard let nextNode = nextValue as? UnboxPathNode else {
throw UnboxPathError.invalidValue(nextValue, key)
throw UnboxPathError.invalidValue(nextValue, components[i])
}

node = nextNode
}

throw UnboxPathError.emptyKeyPath
}
} catch {
Expand All @@ -250,7 +250,7 @@ private extension Unboxer {
} else if let pathError = error as? UnboxPathError {
throw UnboxError.pathError(pathError, path.description)
}

throw error
}
}
Expand Down