2016-09-29 21 views
0

私のコードをSwift 2からSwift 3にアップデートしたところ、SDWebImageのエラーが見つかりました。iOS-Swift 3-SDWebImage

SDWebImageManager.shared().downloadImage(with: URL(string: book.picURL), options: .lowPriority, progress: { (min:Int, max:Int) -> Void in 

      }) { (image:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool, url:NSURL!) -> Void in 
       if image != nil && finished 
       { 

        let obj = cell.keepUrl 
        if obj != nil && url != nil && obj == url 
        { 
         cell.picURL.image = image 
        } 
       } 
      } 

SDWebImageCompletionWithFinishedBlockの定義は、以下の

typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); 

エラーメッセージがされている

「型の値を変換できません「(UIImage!NSError!SDImageCacheType、ブール、NSURL !) - > 'SDWebImageCompletionWithFinishedBlock!'の期待される引数型にVoid '' "

誰も私にこのエラーの解決方法を教えてもらえますか?ありがとう。

答えて

2

完了ブロックの署名はこれです:

あなたは 次の変更加える必要があり
typealias PrefetchingDone = (UIImage?, Error?, SDImageCacheType, Bool, URL?) -> Void 

  1. 変更ErrorからNSErrorを。
  2. 変更!URL
  3. に変更NSURL?

にあなたは、このような方法で書くことができることを使用して:あなたはこのように使用

class func preloadImageWithUrlString(_ urlString: String, fetchedClosure: ImageFetchedClosure? = nil) { 
    let imageURLString = addWidthParameter(urlString, width: width) 
    guard let url = URL(string: imageURLString) else { 
     // Call closure with some error... 
     fetchedClosure(nil, MyError.someCustomErrorHere, SDImageCacheTypeNone, true, nil) 
     return 
    } 

    SDWebImageManager.shared().downloadImage(with: url, options: SDWebImageOptions(rawValue: 0), progress: nil) { 
     (maybeImage, maybeError, cacheType, finished, imageURL) in 
     if let closure = completionClosure { 
      closure(maybeImage, maybeError, cacheType, url) 
     } 
    } 
} 

UIImageView.preloadImageWithUrlString("http://some.url.com/myImage.png") { 
    (maybeImage, maybeError, cacheType, finished, imageURL) in 
    print("prefetching done") 
} 
+0

それをうまくいかなかった... –

+0

何がうまくいかなかったのですか?それはコンパイルされませんでしたか? – Sajjon

+0

'NSError'から' Error'に変更しましたか?私はそれを明確にするために私の答えを更新します – Sajjon