your programing

Swift에서 where in if let 할당 사용

lovepro 2020. 12. 28. 22:14
반응형

Swift에서 where in if let 할당 사용


Swift 매뉴얼 61 페이지에있는 Swift 문서 where는 일반 조건으로 선택적 바인딩을 결합하는 데 사용할 있는 가능성을 암시합니다 . 그러나 그렇게 할 때 where다음 코드와 같이 쉼표로 대체하라는 경고가 표시됩니다 .

if let geocodingError = error as? NSError where geocodingError.code == 2

두 가지 조건의 예

if let x = y, let a = b, a == x && !x.isEmpty {

Swift 3에서는이 구문이 변경되었습니다.

뭐였 어

if let x = y, a = b where a == x {

지금

if let x = y, let a = b, a == x {

정당화는의 각 하위 절이 if ... {이제 독립적 인 부울 테스트라는 것입니다.

이 변경 사항에 대한 자세한 내용은 Xcode 릴리스 노트Swift Evolution 제안 을 참조하십시오.


xcode 9에서

if let str = textField.text as String!, !str.isEmpty
{
   params[key] = str
   TextFieldHelper.setup(textField: textField)
}
else
{ 
   TextFieldHelper.error(textField: textField)
}

참조 URL : https://stackoverflow.com/questions/38762513/usage-of-where-in-if-let-assignment-in-swift

반응형