Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 웹뷰
- darkmode
- Firebase
- geofencing
- Notification
- mac
- SwiftUI
- Xcode
- Swift
- Apple
- window
- Git
- 이미지
- Realm
- 한글
- JPA
- rxswift
- Code
- error
- FLUTTER
- 개발자
- IOS
- UIButton
- appstore
- MacOS
- Session
- github
- view
- Archive
- iOS16
Archives
- Today
- Total
EEYatHo 앱 깎는 이야기
Swift ) 디바이스 여유공간 구하기 - EEYatHo iOS 본문
반응형
다비이스의 여유 저장공간을 단위까지 변환해서 구하는 함수
/// 여유공간 구하기
func getFreeSizeAsString() -> String {
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
var freeSize: NSNumber? // Byte단위
do {
let attributes = try FileManager.default.attributesOfFileSystem(forPath: documentDirectoryPath.last! as String)
freeSize = attributes[FileAttributeKey.systemFreeSize] as? NSNumber
} catch {
print(error)
}
var freeSizeAsDouble: Double = freeSize as? Double ?? 0
if freeSizeAsDouble / 1024 < 1 {
return String(format: "%.1fByte", freeSizeAsDouble)
}
freeSizeAsDouble /= 1024
if freeSizeAsDouble / 1024 < 1 {
return String(format: "%.1fKB", freeSizeAsDouble)
}
freeSizeAsDouble /= 1024
if freeSizeAsDouble / 1024 < 1 {
return String(format: "%.1fMB", freeSizeAsDouble)
}
freeSizeAsDouble /= 1024
return String(format: "%.1fGB", freeSizeAsDouble)
}
'iOS, Swift > Feature' 카테고리의 다른 글
Swift ) xlsx 이미지까지 자유롭게 - EEYatHo iOS (0) | 2022.02.21 |
---|---|
Swift) .CSV 파일 만들기 - EEYatHo iOS (0) | 2022.02.02 |
JPA, Swift ) Apple 로그인 클라-서버 2중 인증 - EEYatHo iOS (1) | 2021.02.27 |
JPA, Swift ) Google 로그인 클라-서버 2중 인증 - EEYatHo iOS (0) | 2021.02.27 |
JPA, Swift ) Kakao 로그인 클라-서버 2중 인증 - EEYatHo iOS (0) | 2021.02.27 |