这是使用的代码不知道为什么会发生此错误,即使我不能将弱自我与结构一起使用。想要存储在 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")
}
}
}