๐ฐfully qualified name
Swift โฉ basic types โฉ function โฉ fully qualified name
add(a: 1, b: 2) // normal call
add(a:b:)(1, 2) // โญ๏ธ fully qualified function name
// ^^^^^^^^^
replit๏ผfully qualified function name
// add()
@discardableResult
func add(a: Int, b: Int) -> Int {
let result = a + b
print(result)
return result
}
// โญ๏ธ assign `add` to variable `add2`
let add2 = add
// โฐโโF.E.โโโฏ (โญ๏ธ F.E.: function expression)
let _ = add2(5, 6) // 11
// โญก
// to silence the compiler warning:
// โ ๏ธ warning: result of call to function returning 'Int' is unused
// ---------------------------------------------------------------------
//
// โญ๏ธ Note:
// despite the presence of `@discardableResult`,
// the warning about `add2()` call is NOT silencedโ
// ---------------------------------
// โญ๏ธ fully qualified function name
// ---------------------------------
add(a: 1, b: 2) // 3
add(a:b:)(1, 2) // 3
// ^^^^^^^^^
// โ
this is OK.
// ---------------------------------------------------------------------
add2(a:b:)(1, 2)
// ^^^^^^^^^^
// โ error: use of unresolved identifier 'add2(a:b:)'
// ---------------------------------------------------------------------
Last updated