Core data Can';在Swift类之间传递核心数据对象

Core data Can';在Swift类之间传递核心数据对象,core-data,swift3,Core Data,Swift3,我有一组核心数据实体,可以成功地从Objective-C VC传递到Swift VC。我已经通过控制台确认他们来了 现在我需要遍历核心数据对象数组,并将它们传递到另一个swift vc。我已将阵列设置为属性(客户是CD实体): var arrcusters:Array=Customer 在我的循环中,我试图将它们传递给另一个Swift VC: for thisCustomer in self.arrCustomers { let gridCell = storyboard.instan

我有一组核心数据实体,可以成功地从Objective-C VC传递到Swift VC。我已经通过控制台确认他们来了

现在我需要遍历核心数据对象数组,并将它们传递到另一个swift vc。我已将阵列设置为属性(客户是CD实体):

var arrcusters:Array=Customer

在我的循环中,我试图将它们传递给另一个Swift VC:

for thisCustomer in self.arrCustomers {

    let gridCell = storyboard.instantiateViewController(withIdentifier: "bulkAddCell") as! BulkAddCell
    resizeGridCell(vGridCell: gridCell.view, frameY: frameY, frameH:50.0)

    gridCell.thisCustomer = thisCustomer

    self.svData.addSubview(gridCell.view)
}
在BulkAddCell中,我将此客户作为一个属性:

var thisCustomer: Customer!
我知道BulkAddCell正在正确初始化,因为我在其中有一些IBOutlet,我可以在控制台中看到它们。但是这个客户总是零


我正在从Obj-C切换到Swift,所以我确信这是我所缺少的基本功能

更改:

var arrCustomers: Array = Customer
var arrCustomers = [Customer]() //init to an empty array of customer objects

//sometime later
//append your arrCustomers with instances of Customer

// before leaving first view controller access the arrCustomers object 
// contents as needed and assign to a corresponding property on the 
// destination view controller. (usually in preparforSegue)
至:

var arrCustomers: Array = Customer
var arrCustomers = [Customer]() //init to an empty array of customer objects

//sometime later
//append your arrCustomers with instances of Customer

// before leaving first view controller access the arrCustomers object 
// contents as needed and assign to a corresponding property on the 
// destination view controller. (usually in preparforSegue)

我已经按这种方式设置了它,但客户的值仍然为零,我也按照您所说的做了,在self.arrData{self.arrcusters.append(value as!customer)}中附加客户数组-->以获取值还可以在此处将Customer对象分配给目标控制器:gridCell.thisCustomer=thisCustomer我可以在self.arrcustomes中看到客户实体,它们永远不会被传递。