A scalable way to remove duplicates from Arrays without extensions in Swift 4 This method is an attempt at removing duplicates from arrays without the use of extensions.
func arrayWithDuplicatesRemoved&lt;T: Equatable&gt;(from array: [T]) -&gt; [T] {
    var results = [T]()
    return array.compactMap { (element) -&gt; T? in
        if results.contains(element) {
            return nil
        } else {
            results.append(element)
            return element
        }
    }
}

let dirty = [&quot;apple&quot;, &quot;kiwi&quot;, &quot;grapefruit&quot;, &quot;kiwi&quot;, &quot;kiwi&quot;, &quot;strawberry&quot;, &quot;watermelon&quot;, &quot;apple&quot;, &quot;banana&quot;]
let clean = arrayWithDuplicatesRemoved(from: dirty)
print(clean) // [&quot;apple&quot;, &quot;kiwi&quot;, &quot;grapes&quot;, &quot;strawberry&quot;, &quot;watermelon&quot;, &quot;banana&quot;]
Your algorithm is O(n^2) so not very scalable... The immediate improvement I can think of is to use a Set for results (which means making T Hashable).

If you aren't worried about position, then just create a Set from an array and you are done.