简体   繁体   中英

Not able to use closure syntax in Swift 3

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:)'

在此处输入图片说明

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 ?

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM