How to use trailing closure in if condition?

后端 未结 2 1691
感情败类
感情败类 2020-12-19 21:43

Here is the code:

class Person {
}

func lastNameForPerson(person: Person, caseFolding: ((String)->(String))? = nil) -> String {
    if let folder = ca         


        
2条回答
  •  难免孤独
    2020-12-19 21:50

    Put your function call between parentheses:

    if "SMITH" == (lastNameForPerson(Person()) {$0.uppercaseString}) {
    

    otherwise the == operator takes precedence and the compiler evaluates it as

    if ("SMITH" == lastNameForPerson(Person())) {$0.uppercaseString} {
    

    which is not valid code.

提交回复
热议问题