If you are looking to do something like set subtraction, Swift has that. See Set operations (union, intersection) on Swift array?.
The title of the SO post above doesn't per se mention the methods subtract(_:)
or subtracting(_:)
, but the content of the accepted answer does cite subtract(_:)
.
In Swift 4.1, You could do something like:
var deviceStartList = ["12345", "67890", "55555", "44444"]
var deviceEndList = ["12345", "55555"]
var deviceStartSet = Set<String>(deviceStartList)
var deviceEndSet = Set<String>(deviceEndList)
let devicesDiff = deviceStartSet.subtracting(deviceEndSet)
And if you need an array as the final output, you can get that by doing this:
var devicesDiffArray = [String](devicesDiff)
Here is a screenshot of a Playground with this working:
