[swift] Swift에서 생성된 디렉토리의 경로 확인하기
다음은 Swift에서 디렉토리의 경로를 확인하는 방법을 보여주는 예제 코드입니다.
import Foundation
// 디렉토리를 확인할 경로
let directoryPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
// 디렉토리의 경로 출력
if let directoryPath = directoryPath {
print("디렉토리 경로: \(directoryPath.path)")
} else {
print("디렉토리를 찾을 수 없음")
}
위의 예제 코드에서는 FileManager.default.urls(for:in:)
메서드를 사용하여 .documentDirectory
를 검색 경로로 지정하고, .userDomainMask
를 검색 옵션으로 지정하여 디렉토리의 URL을 가져옵니다. 그런 다음, 옵셔널 바인딩을 사용하여 디렉토리의 경로를 출력합니다.
이 예제를 참고하여 Swift에서 디렉토리의 경로를 확인할 수 있습니다.