简体   繁体   中英

Cannot call value of non-function type 'Int'

I have this piece of code in Swift (4.2):

let totalQNbr = theArray.reduce(0) {
    (total, arg1) -> Int in
    let (CustomType, Int) = arg1
    let y = arg1.0.val_Number,
    x:Int = Int(y) // Problem line !!!
    return total + x
}

On the line, where I do a ususal type conversion, commented // Problem line !!!

I am getting this error message:

Cannot call value of non-function type 'Int'

Can anybody see what I am supposed to do here?

I have seen a couple of related post, but no clear solution.

That's a great example what happens if you don't conform to the naming convention that variable names have to start with a lowercase letter.

You are declaring a local variable Int – which is not a function – in

let (CustomType, Int) = arg1

It hides the Int struct. Don't do that . Declare variables always starting with a lowercase letter.

let (customType, int) = arg1

However both variables are unused anyway.

And don't annotate types the compiler can infer

x = Int(y)

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