How do I convert an NSData object with hex data to ASCII in Swift?
<p>I have an <code>NSData</code> object with hex data and I want to convert it to an ASCII string. I've seen several similar questions to mine but they are all either in Objective-C and/or they convert a string into hex data instead of the other way around.</p>

<p>I found <a href="https://stackoverflow.com/questions/30793595/how-do-i-convert-a-hex-string-to-its-unicode-ascii-equivalent-in-swift">this function</a> but it doesn't work in Swift 2 and the <a href="https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_Strideable_Protocol/index.html#//apple_ref/swift/intf/s:PSs10Strideable" rel="nofollow noreferrer">Apple documentation</a> doesn't explain the difference between the old <code>stride</code> and the new <code>stride</code> (it doesn't explain stride at all):</p>

<pre><code>func hex2ascii (example: String) -&gt; String
{

    var chars = [Character]()

    for c in example.characters
    {
        chars.append(c)
    }

    let numbers =  stride(from: 0, through: chars.count, by: 2).map{ // error: 'stride(from:through:by:)' is unavailable: call the 'stride(through:by:)' method instead.
        strtoul(String(chars[$0 ..&lt; $0+2]), nil, 16)
    }

    var final = ""
    var i = 0

    while i &lt; numbers.count {
        final.append(Character(UnicodeScalar(Int(numbers[i]))))
        i++
    }

    return final
}
</code></pre>

<p>I don't know what <code>stride</code> is and I don't know what it does.</p>

<p>How do you convert hex to ASCII in Swift 2? Maybe an NSData extension...</p>

<p>Thanks!</p>