Error: Bool is not Convertible to Void:
Your block does not have a return statement, therefore the compiler
uses the result of the last statement
UIApplication.sharedApplication().openURL(url)
as return value, which is a Bool
and not Void
as declared in the block signature.
To solve that problem, just add a return statement:
{ (url: NSURL, oauthToken: String) -> Void in
UIApplication.sharedApplication().openURL(url)
return
}
Bool' is not convertible to '() throws - Bool'
Try .flatMapLatest { element -> <RETURN TYPE> in ...
.
If a flatMap
block contains just a single line, return type - isn't necessary.
Why is the return value of std::getline not convertible to bool?
You didn't add #include <istream>
to your code, so the compiler doesn't know what istream
is and therefore it doesn't know it is convertable to bool
.
Add #include <istream>
to fix the issue.
Swift 2: Bool' is not convertible to 'BooleanLiteralConvertible'
Swift is confused and giving you an incorrect error message. The problem is that the first parameter is of type [UIViewController]?
, so the following should work:
self.pageViewContorller.setViewControllers(viewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
Or even better, declare viewControllers
to be of type [UIViewController]
then no casting is needed in the call:
let viewControllers:[UIViewController] = [startVC]
self.pageViewContorller.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
block in Swift : return error is not convertible to
It's almost working, but you've got a couple things going wrong here. First of all, you can't redeclare a typealias
. Second of all you're calling loadSceneAssetsWithCompletionHandler
as a class function when it's set up as an instance function. Note changes:
typealias OnComplete = (Bool) -> ()
class GameController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
GameScene.loadSceneAssetsWithCompletionHandler { success in
println("2/ yes")
return
}
}
}
class GameScene: UIViewController {
func loadSceneAssets() {
}
class func loadSceneAssetsWithCompletionHandler( completion:OnComplete ) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
let gameScene = GameScene()
gameScene.loadSceneAssets()
dispatch_async(dispatch_get_main_queue()) {
println("1/ yes")
completion(true)
}
}
}
}
How to escape a value with a throw '() throws - Bool' is not convertible to 'Bool'
In your login
method, the type of the parameter authenticated
is @escaping (_ inner: ThrowableCallBack) -> Void
.
So, the closure passed to authenticated
takes one parameter of type ThrowableCallBack
, which means the parameter auth
in your closure is of type ThrowableCallBack
, not Bool
.
You need to use auth
as if try auth()
as ThrowableCallBack
takes one parameter of type ()
and throws
.
func authenticate() {
let services = ServiceManager()
services.login(username: emailField.text!, password: passwordField.text!, authenticated: { auth in
self.loadingDialog.dismiss(animated: false, completion: {
do {
if try auth() {
self.performSegue(withIdentifier: "LoginSegue", sender: self)
}
} catch RequestError.invalidRequest {
self.showLoginFailedAlert()
} catch {
self.showLoginFailedAlert()
}
})
} )
}
To make this work, you may need to modify the type of authenticated
as follows:
func login(username : String, password : String,
authenticated: @escaping (_ inner: @escaping ThrowableCallBack) -> Void ) {
//...
}
Anyway, closure type taking a parameter of another closure type, is very confusing and you should better re-consider your design.
(ADDITION)
When you get runtime errors saying some main thread things, you may need to use DispatchQueue.main
as found in many async examples:
func authenticate() {
let services = ServiceManager()
services.login(username: emailField.text!, password: passwordField.text!, authenticated: { auth in
DispatchQueue.main.async {
self.loadingDialog.dismiss(animated: false, completion: {
do {
if try auth() {
self.performSegue(withIdentifier: "LoginSegue", sender: self)
}
} catch RequestError.invalidRequest {
self.showLoginFailedAlert()
} catch {
self.showLoginFailedAlert()
}
})
}
} )
}
string is not convertible to void
return statusFinale
written in blocks, so retrieveStatusInTable function return Void.
When you use asynchronous method, set function return type "Void" and tell result with blocks (completionHandler).
Sample Code:
func retrieveStatusInTable(name: String, completionHandler:((statusFinale: String) -> Void)) {
// .....
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
// ........
statusFinale = lastFraseStatus
completionHandler(statusFinale: statusFinal)
}
}
Usage:
retrieveStatusInTable("Sample", { (statusFinale) -> Void in
println(statusFinale)
})
Related Topics
Input Type=File Not Working in Webview of Os X Application
Calculate Area of Mkpolygon in an Mkmapview
What Is an Example of Drawing Custom Nodes with Vertices in Swift Scenekit
Find Item of Specific Type in Array
App Crash on Sign in (Xcode 9.3) Exc_Bad_Access (Code=1, Address=0X1)
Wait Until an Asynchronous API Call Is Completed - Swift/Ios
Need to Check That Braces in Given Array Are Balanced or Not
How to Create Text File for Writing
How Is a Return Value of Anyobject! Different from Anyobject
Spritekit - Create at Random Position Without Overlapping
Get Larger Facebook Image Through Firebase Login
Not Condition in 'If Case' Statement
Differences Between "Static Var" and "Var" in Swift
Getting Path for Resource in Command Line Tool
Swift 3, Xcode 8 Instantiate View Controller Is Not Working
Hstack with Sf Symbols Image Not Aligned Centered