Cannot specialize non-generic type 'Set'

佐手、 提交于 2019-12-20 04:25:23

问题


This is my 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 file is created and works however for following declaration:

@NSManaged var orderItem: OrderItem

回答1:


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.

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.

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).



来源:https://stackoverflow.com/questions/38306660/cannot-specialize-non-generic-type-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!