We have next two separated files:
// StoredCompany.swift
import CoreData
import CoreValue
struct StoredCompany: CVManagedPersistentStruct {
static let EntityName = "Company"
var objectID: NSManagedObjectID?
var name: String
var employees: Array<StoredEmployee>
static func fromObject(o: NSManagedObject) throws -> StoredCompany {
return try curry(self.init)
<^> o <|? "objectID"
<^> o <| "name"
<^> o <|| "employees"
}
mutating func save(context: NSManagedObjectContext) throws {
try employees.saveAll(context)
try defaultSave(context)
}
// StoredEmployee.swift
import CoreData
import CoreValue
struct StoredEmployee : CVManagedPersistentStruct {
static let EntityName = "Employee"
var objectID: NSManagedObjectID?
let name: String
let age: Int16
let position: String?
let department: String
let job: String
static func fromObject(o: NSManagedObject) throws -> StoredEmployee {
return try curry(self.init)
<^> o <|? "objectID"
<^> o <| "name"
<^> o <| "age"
<^> o <|? "position"
<^> o <| "department"
<^> o <| "job"
}
}
The compiler throws next error .../StoredCompany.swift:21:20: Cannot invoke 'curry' with an argument list of type '((objectID: NSManagedObjectID?, name: String, employees: Array<StoredEmployee>) -> StoredCompany)'
It's happens only when struct StoredEmployee and struct StoredCompany are in separated files. Probably that's the reason that the tests doesn't catch it.
Cheers! 🍻