0

I am trying to use closure Xcode8 beta4 with Swift3 , but it does not working. Same functions with closure working in Swift2.2, but it fails in Swift3.

Swift 2.2

UIView.animateWithDuration(0.5, animations: {

        self.viewForInstagramLoginWebView.frame = CGRectMake(x, y,self.viewForInstagramLoginWebView.frame.size.width , self.viewForInstagramLoginWebView.frame.size.height)

    }) { (finished) in

        SVProgressHUD.dismiss()
    }

But same syntax not working with Swift3.

Also try by creating function with closure.

func greetingMessageWithDate(date : NSDate, message  :String, successHandler : (greetingMessage : String, code : Int ) -> Void){

}

Same function working in Swift 2.2, but not in Swift 3

Also facing issue with SDWebImage completion block. I am able to use SDWebImage without completion handler, but with completion handler it fails.

Works without completion handler.

imageView.sd_setImage(with: URL(string: "imageURL"), placeholderImage: UIImage(named : "imageName"))

But when using with completion handler, compiler complains with given message.

Ambiguous use of 'sd_setImage(with:placeholderImage:completed:)'

enter image description here

imageView.sd_setImage(with: url, placeholderImage: UIImage(named: "imageName"), completed: { (image, error , cacheType , imageURL) in

        })

It looks like, change would be in closure syntax, but how to find that What is going wrong ?

Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
technerd
  • 14,144
  • 10
  • 61
  • 92

1 Answers1

1

UIView animation syntax changed in Swift 3 to:

UIView.animate(withDuration: 0.5, animations: {

}, completion: { (Bool) in

})

Calling greetingMessageWithDate:

greetingMessageWithDate(date: Date(), message: "") { (greetingMessage: String, code: Int) in

}
M_G
  • 1,208
  • 1
  • 11
  • 16
  • Can you give me solution for `SDWebImage` ? – technerd Aug 16 '16 at 05:41
  • I guess it is not compatible to Swift 3 right now. The regular Swift 3 syntax is not working out of the box. There is also a on open issue regarding Swift 3 support: https://github.com/rs/SDWebImage/issues/1627 – M_G Aug 16 '16 at 07:19
  • Could you mark the answer as correct for the general usage of closures with Swift 3? – M_G Aug 16 '16 at 07:51
  • I am accepting answer for now, but expecting update for `SDWebImage`. Thanks – technerd Aug 16 '16 at 08:38
  • Regarding SDWebImage see this answer for a workaround and detailled explanation: http://stackoverflow.com/a/39024894/2099148 – M_G Aug 18 '16 at 18:17