if let a = b { /// c } 이러한 코드들이 스위프트 오픈소스에 많이 보인다. 필자는 대체 저게 무슨 문법인지 모르겠어서 공부할 때 힘들었었던 경험이 있다. 그래서 알게된 겸 기록하고자 한다. 우선 저건 Optional Binding이라고 하는 문법이며, 위 코드에서 만약 b의 value가 nil이 아닐 때 a에 b의 value가 들어가고 c 부분이 실행된다. 참 편리한 문법인거 같다. 예제를 들어보자면 그렇다고 한다.
extension View { func hideKeyboard() { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } } 위 확장함수를 추가한 다음에 원하는 위치에서 호출하면 된다. 출처: www.hackingwithswift.com/quick-start/swiftui/how-to-dismiss-the-keyboard-for-a-textfield
외주 앱을 만들다가 제목과 같은 오류 때문에 진짜 미치는 줄 알았다! 엄청난 구글링 끝에 결국 해결 법을 찾았다. fileUrl.startAccessingSecurityScopedResource() ... fileUrl.stopAccessingSecurityScopedResource() 이 메서드들을 이용하면 된다. 그렇다면 저 메서드는 무슨 역할을 할까? stackoverflow.com/a/49196035에 따르면 startAccessingSecurityScopedResource() makes the security scoped bookmark's resource available to your app's sandbox thus granting you access to that resource. 라고 ..