如何将NSMutableOrderedSet转换为通用数组? [英] How to covert NSMutableOrderedSet to generic array?
本文介绍了如何将NSMutableOrderedSet转换为通用数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个for循环,p
是NSManagedObject
,fathers
是to-many
关系,所以我需要将NSMutableOrderedSet
强制转换为[Family]
,但是它不起作用,为什么?
I have this for loop, p
is a NSManagedObject
, fathers
is a to-many
relationship, so I need to cast NSMutableOrderedSet
to [Family]
but it does not work, why?
for f in p.fathers as [Family] {
}
推荐答案
您可以通过array
属性获取集合的数组表示形式-然后可以将其向下转换为适当的类型并分配给变量:>
You can obtain an array representation of the set via the array
property - then you can downcast it to the proper type and assign to a variable:
let families = p.fathers.array as [Family]
但是当然您也可以在循环中直接使用它:
but of course you can also use it directly in the loop:
for f in p.fathers.array as [Family] {
....
}
这篇关于如何将NSMutableOrderedSet转换为通用数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文