Swift: SandBox 어플리케이션을 통한 HomeDirectory

2794 단어 SwiftMacOStech
SandBox 애플리케이션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 애플리케이션에서 진정한 홈 디렉토리 파악

좋은 웹페이지 즐겨찾기