Find all combination of string array in swift
<p>I have an Array of String and I want to find all the possible combinations of its element</p>

<blockquote>
  <p>For Example :</p>
  
  <p>Array = [A,B,C,D]</p>
  
  <p>should produce result as :</p>
  
  <p>[A,AB,AC,AD,ABC,ABD,ACD,ABCD,B,BC,BD,BCD,C,CD,D]</p>
</blockquote>

<p>Here is my Logic :</p>

<pre><code>  var array = ["A", "B", "C","D"]
  var list = [String]()
  for i in 0..&lt;array.count{
    let c = array[i]
    list.append(c)
    var d = c
    for count in 1..&lt;array.count{

        if i+count &lt; array.count{
            for j in i+count..&lt;array.count{
                var a = d
                a.appendContentsOf(array[j])
                print("a : \(a)")
                list.append(a)
            }

        }
        d = c
        d.appendContentsOf(array[count])
        print("d : \(d)")
    }
}
print(list.description)
</code></pre>

<blockquote>
  <p>Its Output is :</p>
  
  <p>["A", "AB", "AC", "AD", "ABC", "ABD", "ACD", "B", "BC", "BD", <strong>"BBD"</strong>,
  "C", "CD", "D"]</p>
</blockquote>

<p>This output is missing ABCD and wrongly printed BCD as BBD</p>

<p>Anyone Please Help me in this by Enhancing my code or suggesting your own logic for this.</p>