[iOS] FileManager

RudinP·약 13시간 전
0

Study

목록 보기
261/261

FileManager

  • 파일 처리를 위한 대부분의 Api가 구현되어 있는 클래스
  • 보통은 인스턴스를 만들지 않고 FileManager.default로 공유 인스턴스를 사용한다.
  • 만약 Delegate로 이벤트를 처리해야 한다면 새로운 인스턴스를 만들어야 함

디렉토리에 포함된 항목을 가져올 때

  • url: 파일 주소
  • keys: 함께 가져올 속성 전달. 사용 가능한 속성은 URLResourceKey 구조체에 선언되어있다.
    • localizedNameKey: 파일 이름
    • isDirectoryKey: 디렉토리 플래그
    • fileSizeKey: 파일 사이즈
    • isExcludedFromBackupKey: 백업 여부 플래그
  • mask: 옵션
    • skipsHiddenFiles: 숨겨진 파일들은 스킵
do {
	let properties: [URLResourceKey] = [.localizedNameKey, .isDirectoryKey, .fileSizeKey, .isExcludedFromBackupKey]
    
    let currentContentUrls = try FileManager.default.contentsOfDirectory(at: url,
    	includingPropertiesForKeys: properties,
        options: FileManager.DirectoryEnumerationOptions.skipsHiddenFiles)
        
    for url in currentContentUrls {
    	let content = Content(url:url)
        contents.append(content)
    }
} catch {
	print(error)
}
profile
iOS 개발자가 되기 위한 스터디룸...

0개의 댓글