美文网首页
ImageScout Frame

ImageScout Frame

作者: AlanGit | 来源:发表于2019-06-10 13:12 被阅读0次

    文件结构:

    ImageCount 图片观察对象
    ScoutOperation  图片操作队列
    ImageParser  图片解析
    SessionDelegate  图片下载代理
    

    具体执行过程:

     1、let scout = ImageScout()
    2、 scout.scoutImage(atURL: imagePath) { (error, size, type) -> () in
    
    设置返回时的回调
    3、 operation.completionBlock = { [weak self] in
          completion(operation.error, operation.size, operation.type)
          self?.operations[urlString] = nil
        }
    
    请求数据时 拼接获得到的数据
    4、extension ImageScout {
      func didReceive(data: Data, task: URLSessionDataTask) {
        guard let requestURL = task.currentRequest?.url?.absoluteString else { return }
        guard let operation = operations[requestURL] else { return }
    
        operation.append(data)
        }
    
    //完成时数据开始解析
      func didComplete(with error: NSError?, task: URLSessionDataTask) {
        guard let requestURL = task.currentRequest?.url?.absoluteString,
          let operation = operations[requestURL]
          else { return }
    
        let completionError = error ?? ImageScout.error(withMessage: unableToParseErrorMessage, code: 101)
        operation.terminate(with: completionError)
      }
    }
    

    ImageScout Frame

    相关文章

      网友评论

          本文标题:ImageScout Frame

          本文链接:https://www.haomeiwen.com/subject/rrqzxctx.html