Since I often use this procedure, can someone create a Swift array extension method that will determine if the data to be added already exists, then it is not added? I know that these are just a few of these codes:
var arr = [Int]()
for element in inputArr {
if !arr.contains(element) { arr.append(element); }
}
becomes:
var arr = [Int]()
for element in inputArr { arr.appendUnique(element); }
Or:
var arr = [String]()
for element in inputArr {
if !arr.contains(element) { arr.append(element); }
}
becomes:
var arr = [String]()
for element in inputArr { arr.appendUnique(element); }
The same method for different types of elements. Honestly, from this simple code I also want to learn how to extend with Collection
variable types. I admire how Array methods can have different types of parameters when an object was initialized with different types of parameters. An array and a dictionary are two things that I still do not understand how to expand them correctly. Thank you