Date
1 - 5 of 5
New syntax in Xcode 12.5.
Alex Zavatone
I just saw someone use this syntax in a project and haven’t see it before. It compiles in Xcode 12.5, but not in Xcode 12.4. Does anyone have any more details on it?
let myVar = myVar != someValue ? resultOne : resultTwo Swift sure is getting muddier and muddier with regards to visual comprehension. Thanks in advance. Alex Zavatone |
|
Jeremy Hughes
Are you referring to the ternary conditional operator, which has existed in Swift since the beginning, or to the fact that it creates a local variable with the same name (myVar) as a parameter or member (myVar)?
toggle quoted message
Show quoted text
Jeremy — On 26 Jul 2021, at 15:37, Alex Zavatone via groups.io <zav@...> wrote: |
|
Alex Zavatone
The first half. Ternary has been there since time began. I’ve never seen this part be legitimate before.
toggle quoted message
Show quoted text
let myVar = myVar != someValue On Jul 26, 2021, at 10:09 AM, Jeremy Hughes via groups.io <moon.rabbit@...> wrote: |
|
Jeremy Hughes
1. myVar != someValue is the condition.
toggle quoted message
Show quoted text
2. It determines whether the ternary expression evaluates to resultOne or resultTwo 3. resultOne or resultTwo is what is assigned in let myVar = This seems like a standard use of the ternary conditional operator. I don’t have any problems compiling it in Xcode 12.4. Jeremy — On 26 Jul 2021, at 16:57, Alex Zavatone via groups.io <zav@...> wrote: |
|
Alex Zavatone
I found out what the issue was. The programmer didn’t add a self in front of variables that had the same name as the local that he was creating. Xcode 12.4 reports an error until you add self in front of the properties. Xcode 12.5 can handle
toggle quoted message
Show quoted text
The actual line looked more like this. let myVar = myVar != someValue ? myVar : myOtherAssignment It actually should be let myVar = self.myVar != someValue ? self.myVar : myOtherAssignment Thanks. Alex Zavatone
|
|