@@ -4,7 +4,7 @@ public protocol Initializable : class {
4
4
}
5
5
6
6
/// Create a class or struct with a constructor method. Return a value of `property.type` for each property. Classes must conform to `Initializable`.
7
- public func construct< T> ( _ type: T . Type = T . self, constructor: Property . Description throws -> Any ) throws -> T {
7
+ public func construct< T> ( _ type: T . Type = T . self, constructor: ( Property . Description ) throws -> Any ) throws -> T {
8
8
guard Metadata ( type: T . self) . isStructOrClass else { throw Error . notStructOrClass ( type: T . self) }
9
9
if Metadata ( type: T . self) ? . kind == . struct {
10
10
return try constructValueType ( constructor)
@@ -15,7 +15,7 @@ public func construct<T>(_ type: T.Type = T.self, constructor: Property.Descript
15
15
}
16
16
}
17
17
18
- private func constructValueType< T> ( _ constructor: Property . Description throws -> Any ) throws -> T {
18
+ private func constructValueType< T> ( _ constructor: ( Property . Description ) throws -> Any ) throws -> T {
19
19
guard Metadata ( type: T . self) ? . kind == . struct else { throw Error . notStructOrClass ( type: T . self) }
20
20
let pointer = UnsafeMutablePointer < T > ( allocatingCapacity: 1 )
21
21
defer { pointer. deallocateCapacity ( 1 ) }
@@ -25,15 +25,15 @@ private func constructValueType<T>(_ constructor: Property.Description throws ->
25
25
return pointer. pointee
26
26
}
27
27
28
- private func constructReferenceType< T> ( _ value: T , constructor: Property . Description throws -> Any ) throws -> T {
28
+ private func constructReferenceType< T> ( _ value: T , constructor: ( Property . Description ) throws -> Any ) throws -> T {
29
29
var copy = value
30
30
var storage = mutableStorageForInstance ( & copy)
31
31
var values = [ Any] ( )
32
32
try constructType ( storage: & storage, values: & values, properties: properties ( T . self) , constructor: constructor)
33
33
return copy
34
34
}
35
35
36
- private func constructType( storage: inout UnsafeMutablePointer < Int > , values: inout [ Any ] , properties: [ Property . Description ] , constructor: Property . Description throws -> Any ) throws {
36
+ private func constructType( storage: inout UnsafeMutablePointer < Int > , values: inout [ Any ] , properties: [ Property . Description ] , constructor: ( Property . Description ) throws -> Any ) throws {
37
37
for property in properties {
38
38
var value = try constructor ( property)
39
39
guard Reflection . value ( value, is: property. type) else { throw Error . valueIsNotType ( value: value, type: property. type) }
@@ -47,7 +47,7 @@ public func construct<T>(_ type: T.Type = T.self, dictionary: [String: Any]) thr
47
47
return try construct ( constructor: constructorForDictionary ( dictionary) )
48
48
}
49
49
50
- private func constructorForDictionary( _ dictionary: [ String : Any ] ) -> Property . Description throws -> Any {
50
+ private func constructorForDictionary( _ dictionary: [ String : Any ] ) -> ( Property . Description ) throws -> Any {
51
51
return { property in
52
52
if let value = dictionary [ property. key] {
53
53
return value
0 commit comments