 <p>I can not fully explain it, but the problem seems to be that <code>session.downloadTaskWithURL(url)</code> returns an instance of some internal subclass <code>__NSCFLocalDownloadTask</code>.</p> <p>If you define the extension as an extension of <code>NSURLSessionTask</code> instead of <code>NSURLSessionDownloadTask</code> </p> <pre><code>extension NSURLSessionTask { ... } </code></pre> <p>then it worked in my test.</p>