Question: I understand from my recent use of PHP-PDO over the last few months that you can do a PREPARE statement and then run the query. In fact I can see the usefulness of this if I'm going to either SELECT on a complex join, varying the where conditions, a repeated number of times.

Or, similarly, if I was wanting to insert multiple records.

However, if I know I only want to run a statement once, shouldn't I just EXECUTE the query? I'm basically querying the database twice.

Answer: 
As of Swift 1.2 (Xcode 6.3 beta), Swift has a native set type.
From the release notes:

> 
> A new `Set` data structure is included which provides a generic
>  collection of unique elements, with full value semantics. It bridges
>  with `NSSet`, providing functionality analogous to `Array` and `Dictionary`.
> 
> 
> 

Here are some simple usage examples:

```
// Create set from array literal:
var set = Set([1, 2, 3, 2, 1])

// Add single elements:
set.insert(4)
set.insert(3)

// Add multiple elements:
set.unionInPlace([ 4, 5, 6 ])
// Swift 3: set.formUnion([ 4, 5, 6 ])

// Remove single element:
set.remove(2)

// Remove multiple elements:
set.subtractInPlace([ 6, 7 ])
// Swift 3: set.subtract([ 6, 7 ])

print(set) // [5, 3, 1, 4]

// Test membership:
if set.contains(5) {
    print("yes")
}

```

but there are far more methods available.

**Update:** Sets are now also documented in the ["Collection Types"](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html) chapter of the Swift documentation.
I wrote a function to solve this problem.

```
public func removeDuplicates<C: ExtensibleCollectionType where C.Generator.Element : Equatable>(aCollection: C) -> C {
    var container = C()

    for element in aCollection {
        if !contains(container, element) {
            container.append(element)
        }
    }

    return container
}

```

To use it, just pass an array which contains duplicate elements to this function. And then it will return a uniqueness-guaranteed array.

You also can pass a `Dictionary`, `String` or anything conforms to `ExtensibleCollectionType` protocol if you like.