Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making contextType optional in UnmarshalingWithContext and UnmarshalUpdatingWithContext protocols #83

Open
wants to merge 1 commit 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
12 changes: 6 additions & 6 deletions Sources/UnmarshalingWithContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public protocol UnmarshalingWithContext {
associatedtype ContextType
associatedtype ConvertibleType = Self

static func value(from object: MarshaledObject, inContext context: ContextType) throws -> ConvertibleType
static func value(from object: MarshaledObject, inContext context: ContextType?) throws -> ConvertibleType
}

public protocol UnmarshalUpdatingWithContext {
associatedtype ContextType
mutating func update(object: MarshaledObject, inContext context: ContextType) throws
mutating func update(object: MarshaledObject, inContext context: ContextType?) throws
}

extension MarshaledObject {
public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType) throws -> A {
public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType?) throws -> A {
let any = try self.any(for: key)
guard let object = any as? MarshaledObject else {
throw MarshalError.typeMismatch(expected: MarshaledObject.self, actual: type(of: any))
Expand All @@ -37,7 +37,7 @@ extension MarshaledObject {
return value
}

public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType) throws -> A? {
public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType?) throws -> A? {
do {
let a: A = try self.value(for: key, inContext: context)
return a
Expand All @@ -50,7 +50,7 @@ extension MarshaledObject {
}
}

public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType) throws -> [A] {
public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType?) throws -> [A] {
let any = try self.any(for: key)
guard let objectArray = any as? [AnyObject] else {
throw MarshalError.typeMismatch(expected: Array<MarshaledObject>.self, actual: type(of: any))
Expand All @@ -66,7 +66,7 @@ extension MarshaledObject {
}
}

public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType) throws -> [A]? {
public func value<A: UnmarshalingWithContext>(for key: KeyType, inContext context: A.ContextType?) throws -> [A]? {
do {
return try self.value(for: key, inContext: context) as [A]
}
Expand Down