swift개발2 Initializer for conditional binding must have Optional type, not 'String' 상단의 코드에서 if let docuPath = directory.path로 잡아주게 되면 제목과 같이 조건부 바인딩의 초기자(initializer)는 옵셔널형이어야하며, String일수 없다는 에러가 뜹니다. 있을지 없을지도 모르는데 어떻게 저렇게 쓰니? 하는 것이죠... let docuPath = directory.path if !docupath.isEmpty { let fileNames = try FileManager.default.contentsOfDirectory(atPath: docuPath) for fileName in fileNames { if fileName == named { let filePathName = "\(docuPath)/ \(fileName)" try FileManager... 2022. 12. 22. UIImage nil 확인하기(optional, non-optional) var image = UIImage() if image != nil { print("this image is not nil") } Comparing non-optional value of type 'UIImage' to 'nil' always returns false image를 옵셔널로 정의하지 않은 상태에서 nil인지 아닌지를 물어보는 것은 의미가 없습니다. 해당 이미지를 nil인지 아닌지를 확인하기 위해서는 선언할 때에 아래와 같이 옵셔널로 남겨둔 다음 처리가 가능합니다. var image: UIImage? = UIImage() if image != nil { print("this image is not nil") } 만약 불가피한 경우라면 아래와 같이 우회하는 방법을 써서 확인이 가능합니다. va.. 2022. 12. 21. 이전 1 다음