args.resume_扩展URLSession,再也不会忘记.resume()

本文翻译自Medium,介绍了如何扩展URLSession,确保在下载操作中始终记得调用.resume()方法,避免因忘记该调用而导致的下载中断问题。
摘要由CSDN通过智能技术生成

args.resume

不再有.resume()-根据需要使用模拟数据-或根据需要实时数据 (No more .resume() — Use Mock Data as you please — Or Live data if you need)

If you work with networking in Swift, chances are you’ve used URLSession. Chances are also that you’ve spent 1, 2 or a hundred minutes debugging a call that just wouldn’t fire! Then you sheepishly realized you forgot .resume() at the end of your dataTask…

如果您在Swift中使用网络,则很有可能使用过URLSession。 也有可能您花了1、2或一百分钟来调试不会触发的呼叫 然后,您令人毛骨悚然地意识到,在dataTask的末尾忘记了.resume()…

为什么我甚至需要.resume()? (Why do I even need .resume() ?)

If you look carefully at the way we do a network call, we aren’t immediately doing anything with the code inside of our dataTask. The dataTask method returns a URLSessionDataTask object that you can use for Asynchronous operations.

如果仔细看一下我们进行网络调用的方式,我们不会立即对dataTask内部的代码执行任何操作。 dataTask方法返回可用于异步操作的URLSessionDataTask对象。

URLSession.shared.dataTask returns something!
URLSession.shared.dataTask returns something!
URLSession.shared.dataTask返回一些信息!

Once you call one of the methods on dataTask, things begin to happen. Focusing on our “culprit” here, the resume method…

一旦调用dataTask的方法之一,事情就会开始发生。 在这里关注我们的“罪魁祸首”,简历方法……

URLSessionDataTask inherit

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值