1

在此处输入图像描述

这是使用的代码不知道为什么会发生此错误,即使我不能将弱自我与结构一起使用。想要存储在 selectedicon URL 上存在的图像的黑白图像:

struct ServiceViewModel {

  private var service: Service
  var selectedicon: URL?
  var name: String
  var subServiceCount: Int {
   return service.subServices.count
  }
  var subServicesViewModel = [SubServiceViewModel]()
  var blackWhiteImage: UIImage?
  var isSelected: Bool = false
  init(service: Service) {
    self.service = service
    self.selectedicon = URL(string: service.icon)
    self.name = service.name

  }
  mutating func generateBlackAndWhiteImage() {
    guard let url = selectedicon else {
      return
    }
    KingfisherManager.shared.retrieveImage(with: url, options: nil, progressBlock: nil) { (image, error, _, _) in
      //self.blackWhiteImage = image?.convertBlackAndWhite()
      self.blackWhiteImage = #imageLiteral(resourceName: "IM.png")
    }
  }


}
4

1 回答 1

1
 let `self` = self 
 // or
 let `self` = UnsafeMutablePointer(&self)  
 KingfisherManager.shared.retrieveImage(with: url, options: nil, progressBlock: nil) { 
 (image, error, _, _) in
      //self.blackWhiteImage = image?.convertBlackAndWhite()
      self.blackWhiteImage = #imageLiteral(resourceName: "IM.png")   
      // or
      self.pointee.blackWhiteImage = image?.convertBlackAndWhite()
  }    
于 2018-07-06T05:38:34.760 回答