Functions

let candy: Array = [4 ]

 let fruits: Array = [6]



func mySweets (itemOne: Int , itemTwo: Int) -> String {

   

    let allSweets = candy + fruits

    

    for _ in allSweets {

        print(allSweets)

    }

return (" this \(allSweets) " )

}



mySweets(itemOne:candy , itemTwo: fruits) - *Type of expression is ambiguous without more context Why i'm receiving this?
Answered by DTS Engineer in 672427022

Why i'm receiving this?

I’m not 100% sure. When I put your code into a playground (Xcode 12.5) I get a different error:

Code Block
mySweets(itemOne:candy , itemTwo: fruits)
^
cannot convert value of type '[Int]' to expected argument type 'Int'


That one makes sense. The itemOne parameter of the mySweets(…) function is declared to be an Int, but you’re trying to call it with candy, which is declared as an [Int], that is, an array of Int.

Reading the rest of your code I think you’ll want to change mySweets(…) to take two arrays rather than two Int values, that is:

Code Block
func mySweets(itemOne: [Int], itemTwo: [Int]) -> String …


ps It helps if you put your code in a code block (surround it by triple backticks, or just click the Code Block button in the editor) because that’s much easier to read.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Accepted Answer

Why i'm receiving this?

I’m not 100% sure. When I put your code into a playground (Xcode 12.5) I get a different error:

Code Block
mySweets(itemOne:candy , itemTwo: fruits)
^
cannot convert value of type '[Int]' to expected argument type 'Int'


That one makes sense. The itemOne parameter of the mySweets(…) function is declared to be an Int, but you’re trying to call it with candy, which is declared as an [Int], that is, an array of Int.

Reading the rest of your code I think you’ll want to change mySweets(…) to take two arrays rather than two Int values, that is:

Code Block
func mySweets(itemOne: [Int], itemTwo: [Int]) -> String …


ps It helps if you put your code in a code block (surround it by triple backticks, or just click the Code Block button in the editor) because that’s much easier to read.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Functions
 
 
Q