Skip to content

Commit

Permalink
Enable nested context to be used when unboxing array of nested Unboxa…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
JohnSundell committed Jul 25, 2016
1 parent f8568ce commit 8578fde
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Unbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,16 @@ public class Unboxer {
}

/// Unbox a required Array of nested Unboxables, by unboxing an Array of Dictionaries and then using a transform (optionally allowing invalid elements)
public func unbox<T: Unboxable>(key: String, isKeyPath: Bool = true, allowInvalidElements: Bool = false) -> [T] {
public func unbox<T: Unboxable>(key: String, isKeyPath: Bool = true, context: Any? = nil, allowInvalidElements: Bool = false) -> [T] {
return UnboxValueResolver<[UnboxableDictionary]>(self).resolveRequiredValueForKey(key, isKeyPath: isKeyPath, fallbackValue: [], transform: {
return try? Unbox($0, context: self.context, allowInvalidElements: allowInvalidElements)
return try? Unbox($0, context: context ?? self.context, allowInvalidElements: allowInvalidElements)
})
}

/// Unbox an optional Array of nested Unboxables, by unboxing an Array of Dictionaries and then using a transform (optionally allowing invalid elements)
public func unbox<T: Unboxable>(key: String, isKeyPath: Bool = true, allowInvalidElements: Bool = false) -> [T]? {
public func unbox<T: Unboxable>(key: String, isKeyPath: Bool = true, context: Any? = nil, allowInvalidElements: Bool = false) -> [T]? {
return UnboxValueResolver<[UnboxableDictionary]>(self).resolveOptionalValueForKey(key, isKeyPath: isKeyPath, transform: {
return try? Unbox($0, context: self.context, allowInvalidElements: allowInvalidElements)
return try? Unbox($0, context: context ?? self.context, allowInvalidElements: allowInvalidElements)
})
}

Expand Down

0 comments on commit 8578fde

Please sign in to comment.