Find unique values in a Swift Array
<p>I am building a project that tells me the unique words in a piece of text.</p>

<p>I have my orginal string <em>scriptTextView</em> which I have added each word into the array <em>scriptEachWordInArray</em></p>

<p>I would now like to create an array called <em>scriptUniqueWords</em> which only includes words that appear once (in other words are unique) in <em>scriptEachWordInArray</em></p>

<p>So I'd like my scriptUniqueWords array to equal = ["Silent","Holy"] as a result.</p>

<p><strong>I don't want to create an array without duplicates but an array that has only values that appeared once in the first place.</strong></p>

<pre><code>var scriptTextView = "Silent Night Holy Night"
var scriptEachWordInArray = ["Silent", "night", "Holy", "night"]
var scriptUniqueWords = [String]()

for i in 0..&lt;scriptEachWordInArray.count {

    if scriptTextView.components(separatedBy: "\(scriptEachWordInArray[i]) ").count == 1 {
        scriptUniqueWords.append(scriptEachWordInArray[i])
        print("Unique word \(scriptEachWordInArray[i])")}

}
</code></pre>