无法专门化非通用类型“设置" [英] Cannot specialize non-generic type 'Set'
问题描述
这是我的NSManagedObject
:
@objc(Order)
class Order: NSManagedObject {
@NSManaged var orderItems: Set<OrderItem> //error: Cannot specialize non-generic type 'Set'
}
有人知道为什么它不起作用吗?
Anyone know why it doesnt work?
OrderItem
文件已创建,并且可用于以下声明:
OrderItem
file is created and works however for following declaration:
@NSManaged var orderItem: OrderItem
推荐答案
仅供参考,如果将来有人因为这个令人讨厌的bug而要问这个问题,因为讨论一直在评论中进行.
Just for reference if someone should come to this question in the future for this nasty bug, since the discussion went on in the comments.
是的,Swift中默认的Set
类型是泛型的,但是在这种情况下,自定义的非泛型Set
类遮盖了该语言的标准库所定义的类.
Yes, the default Set
type in Swift is generic, but in this case a custom non-generic Set
class was shadowing the class defined by the language's standard library.
最好为您的班级选择不同的名称,以避免名称冲突.但是,如果需要,您可以始终使用类的完全限定名称来引用所需的类.
Better always choose different names for your classes, to avoid name clashes. But if needed, you can always use the fully qualified name of the classes to refer to the class you want.
标准语言类在Swift.
命名空间下可用,而对于其他类,您可以使用模块名称,后跟点和类名称(例如Foundation.NSString).
Standard language classes are available under the Swift.
namespace, while for other classes you can use the name of the module followed by a dot and the name of the class (e.g. Foundation.NSString).
这篇关于无法专门化非通用类型“设置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!