Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmes committed May 12, 2016
1 parent 556a2ed commit 22e9dd9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/Construct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public protocol Initializable : class {
}

/// Create a class or struct with a constructor method. Return a value of `property.type` for each property. Classes must conform to `Initializable`.
public func construct<T>(_ type: T.Type = T.self, constructor: Property.Description throws -> Any) throws -> T {
public func construct<T>(_ type: T.Type = T.self, constructor: (Property.Description) throws -> Any) throws -> T {
guard Metadata(type: T.self).isStructOrClass else { throw Error.notStructOrClass(type: T.self) }
if Metadata(type: T.self)?.kind == .struct {
return try constructValueType(constructor)
Expand All @@ -15,7 +15,7 @@ public func construct<T>(_ type: T.Type = T.self, constructor: Property.Descript
}
}

private func constructValueType<T>(_ constructor: Property.Description throws -> Any) throws -> T {
private func constructValueType<T>(_ constructor: (Property.Description) throws -> Any) throws -> T {
guard Metadata(type: T.self)?.kind == .struct else { throw Error.notStructOrClass(type: T.self) }
let pointer = UnsafeMutablePointer<T>(allocatingCapacity: 1)
defer { pointer.deallocateCapacity(1) }
Expand All @@ -25,15 +25,15 @@ private func constructValueType<T>(_ constructor: Property.Description throws ->
return pointer.pointee
}

private func constructReferenceType<T>(_ value: T, constructor: Property.Description throws -> Any) throws -> T {
private func constructReferenceType<T>(_ value: T, constructor: (Property.Description) throws -> Any) throws -> T {
var copy = value
var storage = mutableStorageForInstance(&copy)
var values = [Any]()
try constructType(storage: &storage, values: &values, properties: properties(T.self), constructor: constructor)
return copy
}

private func constructType(storage: inout UnsafeMutablePointer<Int>, values: inout [Any], properties: [Property.Description], constructor: Property.Description throws -> Any) throws {
private func constructType(storage: inout UnsafeMutablePointer<Int>, values: inout [Any], properties: [Property.Description], constructor: (Property.Description) throws -> Any) throws {
for property in properties {
var value = try constructor(property)
guard Reflection.value(value, is: property.type) else { throw Error.valueIsNotType(value: value, type: property.type) }
Expand All @@ -47,7 +47,7 @@ public func construct<T>(_ type: T.Type = T.self, dictionary: [String: Any]) thr
return try construct(constructor: constructorForDictionary(dictionary))
}

private func constructorForDictionary(_ dictionary: [String: Any]) -> Property.Description throws -> Any {
private func constructorForDictionary(_ dictionary: [String: Any]) -> (Property.Description) throws -> Any {
return { property in
if let value = dictionary[property.key] {
return value
Expand Down

0 comments on commit 22e9dd9

Please sign in to comment.