Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot specialize non-generic type 'Set'

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
like image 927
Bartłomiej Semańczyk Avatar asked Nov 04 '25 21:11

Bartłomiej Semańczyk


1 Answers

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

like image 75
uraimo Avatar answered Nov 06 '25 15:11

uraimo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!