func oneStepForward(_ input: Int) -> Int {
return input + 1
}
func oneStepBackward(_ input: Int) -> Int {
return input - 1
}
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
return backward ? oneStepBackward : oneStepForward
//Error. type of expression is ambiguous without a type annotation
}
Why am I getting this error ?
If I change this function to the following it works and will compile.
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
if backward {
return oneStepBackward
} else {
return oneStepForward
}
}
// Why am I getting the error in the previous version while it works in the second version ?
Thx in advance.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Greetings,
func stepForward(_ input: Int) -> Int {
return input + 1
}
func stepBackward(_ input: Int) -> Int {
return input - 1
}
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
return backward ? stepBackward : stepForward /* Error
type of expression is ambiguous without a type annotation */
}
Why am I getting this error. If I change the function to
func chooseStepFunction(backward: Bool) -> (Int) -> Int {
if backward {
return stepBackward
else {
return stepForward
}
}
Why is the previous chooseStepFunction giving me an error ?
Thx in advance
I really like the swift color syntax in the editor window of Xcode . The trouble is it constantly stops working . I have to choose the swift color syntax from the menu to get it to work again . Works for a short (Very short) while and then stops working again . Very annoying . Also the live error reporting in the swift editor window (which I also like very much) of the Xcode IDE constantly stops working . I have to quit Xcode (Usually force quit) and restart it to get it working again . Very annoying . Xcode has been out for many years now and I am sure Apple is pouring a lot resources into it . These constant bugs (which hit you right in the face) should have been resolved by now. They have no excuse .