Swift: SandBox 어플리케이션을 통한 HomeDirectory
NSHomeDirectory()
이면 원래 홈 디렉토리의 경로를 가져올 수 없습니다.대체로, 사용
getpwuid(getuid())
하면 얻을 수 있다.extension FileManager {
static var homeDirectoryURL: URL? {
guard let pw = getpwuid(getuid()), let home = pw.pointee.pw_dir else { return nil }
let homePath = self.default.string(withFileSystemRepresentation: home,
length: strlen(home))
return URL(fileURLWithPath: homePath)
}
}
let home = FileManager.homeDirectoryURL
같은 결론을 얻은 문장App Sandbox의 MacOS 애플리케이션에서 진정한 홈 디렉토리 파악
Reference
이 문제에 관하여(Swift: SandBox 어플리케이션을 통한 HomeDirectory), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/kyome/articles/f51823f54f12d9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)