jamfer
V2EX  ›  问与答

Swift 中用 OperationQueue 开了一个独立线程下载图片,如何返回结果?

  •  
  •   jamfer · Jul 20, 2017 · 1408 views
    This topic created in 3219 days ago, the information mentioned may be changed or developed.
    //下载图片的类
    let imgdown = imgdownload(imgurl:imgurl)
    //加入到独立线程里去
    imgoper.downloadQueue.addOperation(imgdown)

    imgdownload 类中主要执行了

    let imgu = URL(string:imgurl)
    let imgd = try? Data(contentsOf:imgu!)

    现在因为我需要对下载完毕的图片进行处理,怎么在线程执行完毕之后返回执行结果( imgd )呢?

    PS:没有用独立线程之前我是直接在方法里加上 -> Data 来返回 Imgd 的,但现在显然不能这么做了
    1 replies    2017-07-20 13:54:59 +08:00
    jamfer
        1
    jamfer  
    OP
       Jul 20, 2017
    自顶一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2836 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 15:30 · PVG 23:30 · LAX 08:30 · JFK 11:30
    ♥ Do have faith in what you're doing.