Not able to use closure syntax in Swift 3

690 Views Asked by At

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 ?

1

There are 1 best solutions below

5
On BEST ANSWER

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

}