Understanding Swift Functions (Arguments)

Asked 2 years ago, Updated 2 years ago, 38 views

It was during practice at Myplayground.(https://i.stack.imgur.com/CXHAv.jpg)
I've just started the programming grammar on swift, and it's a basic one, but I don't know why I get an error.

swift

2022-09-30 19:10

1 Answers

When Swift2 changed to Swift3, the calling convention of the function was changed.Swift2 omitted the argument name label by default for the first argument only (which was close to Objective-C naming convention), but Swift3 needed to label the first argument with an external argument name to prioritize grammatical consistency.

https://github.com/apple/swift-evolution/blob/master/proposals/0046-first-label.md

In other words, areaOfTrianableWithBase(3,andHeight:4) is correct on Swift2, but compilation error on Swift3.

Correctly label the first argument with an external argument name and call it as follows:

areaOfTribleWithBase(base:3, andHeight:4)


2022-09-30 19:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.