Xcode 获取托管对象的多个关系属性作为托管对象的数组(而不是OrderedSet)

Xcode 获取托管对象的多个关系属性作为托管对象的数组(而不是OrderedSet),xcode,core-data,swift4,Xcode,Core Data,Swift4,我在核心数据中有一个集合和一个成员托管对象。 集合有一个对多关系成员,可以包含成员对象成员对象应与单个集合唯一关联 我希望能够将此关系中的对象用作托管对象,用于填充我的表视图控制器,如下所示: 让成员:[Member]=someCollection.members 但是,members属性似乎是一个sensorderedset?对象,而不是成员的数组 在这种程度上,我尝试了以下方法(在互联网上找到的,因为我对Swift非常陌生),并且我还试图抓住关系字段可能为nil的情况。这对我不起作用,我不明

我在核心数据中有一个
集合
和一个
成员
托管对象。
集合
有一个对多关系
成员
,可以包含
成员
对象<代码>成员对象应与单个
集合
唯一关联

我希望能够将此关系中的对象用作托管对象,用于填充我的表视图控制器,如下所示:

让成员:[Member]=someCollection.members

但是,
members
属性似乎是一个
sensorderedset?
对象,而不是
成员的数组

在这种程度上,我尝试了以下方法(在互联网上找到的,因为我对Swift非常陌生),并且我还试图抓住关系字段可能为
nil
的情况。这对我不起作用,我不明白为什么

let members = someCollection.members?.array as! [Member]

if members != nil {
//Do something with the array

else {
//handle the case that there is no entry in the relationship field
}
我得到以下错误:

线程1:致命错误:在展开可选值时意外发现nil


请帮助我了解我做错了什么,如果可能的话,提供一个解决方案。

由于
数组
返回一个非可选的值,您必须选择绑定
成员
。如果检查成功,您可以安全地强制展开阵列。代码还会检查数组是否为空

if let members = someCollection.members, members.count > 0 {
   let memberArray = members.array as! [Member]
   //Do something with the array
else {
   //handle the case that there is no entry in the relationship field
}

由于
数组
返回一个非可选的值,因此必须对
成员进行可选绑定
。如果检查成功,您可以安全地强制展开阵列。代码还会检查数组是否为空

if let members = someCollection.members, members.count > 0 {
   let memberArray = members.array as! [Member]
   //Do something with the array
else {
   //handle the case that there is no entry in the relationship field
}

我试过了,但是我得到了类型为'sensorderedset'的
值没有成员'isEmpty'
我试过了,但是我得到了类型为'sensorderedset'的
值没有成员'isEmpty'