ios – Swift, Set extension error: Type of expression is ambiguous without a type annotation?


In Swift, I would like to make an extension on Set that takes two arrays, and the function needs to add the elements from one array and remove elements found in another array to the called upon Set.

extension Set {
    
    mutating func update<T>(adding a:[T], removing b:[T]) where T:Hashable {
        var r = union(Set<T>(a)) // ERROR: Type of expression is ambiguous without a type annotation
        r.subtract(Set<T>(b))
        self = r
    }
    
}

I currently get this error: Type of expression is ambiguous without a type annotation.

How can I fix this so that the Set instance I call this on will update accordingly?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img