Original StackOverflow post: https://stackoverflow.com/questions/46924554/redundant-superclass-constraint-in-swift-4
I'm getting a Redundant superclass constraint... warning in swift4: (paste in a playground) import CoreData class Item : NSManagedObject {} protocol DataSourceProtocol { associatedtype DataSourceItem : NSManagedObject } protocol DataSourceProtocolProvider : class { } extension DataSourceProtocolProvider { func createDataSource<T: DataSourceProtocol>(dataSource: T) where T.DataSourceItem == Item { } } On the createDataSource<T: DataSourceProtocol> declaration I get the following warning: Redundant superclass constraint 'T.DataSourceItem' : 'NSManagedObject' I thought that you could specify that an associatedtype could be used with the == operator to constrain the associatedtype to a specific type. I want to have a func createDataSource<T: DataSourceProtocol>(dataSource:T) where the DataSourceItem is an Item. If I replace the == operator with : then the warning goes away: extension DataSourceProtocolProvider { func createDataSource<T: DataSourceProtocol>(dataSource: T) where T.DataSourceItem : Item { } } This happens to be a completely different context now. This constraint specifies that I want to have a func createDataSource<T: DataSourceProtocol>(dataSource:T) where the DataSourceItem is a subclass of Item. Which isn't the same thing as DataSourceItem is an Item object. Also, the code runs fine with == so am I just not understanding how constraints work?
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users