최근에 앱을 만들때, 로컬저장소 UserDefaults를 이용하다가 SQLite로 변경한 적이 있었다.
오토레이아웃을 확인하고, 앱 사용자의 느낌을 받기위해 핸드폰에 직접 넣고 돌려봤는데 DB생성오류가 계속 뜨는것이었다.
열심히 구글링 해본 결과 아래 사이트에서 도움을 받았다.
https://stackoverflow.com/questions/67097212/sqlite-db-create-error-in-real-ios-device
SQLite db create error in real iOS device
I'm trying to learning swiftUi and I've included SQLIte in my project. I've successfully created db, tables and func to read and insert records and I tested it in Xcode emulator and all works fine....
stackoverflow.com
이전코드:
let filePath = try! FileManager.default.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false).appendingPathExtension(databaseName).path
바꾼코드:
let path = try! FileManager.default.url(for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true).appendingPathComponent(databaseName).path
.documentDirectory: 사용자 대상파일, .applicationSupportDirectory: 앱의 지원파일로 후자가 적합하다고 한다.
applicationSupportDirectory로 바꿔주니 데이터베이스가 정상적으로 만들어졌다.
https://developer.apple.com/documentation/foundation/filemanager/searchpathdirectory
FileManager.SearchPathDirectory | Apple Developer Documentation
The location of significant directories.
developer.apple.com
https://developer.apple.com/documentation/foundation/filemanager
FileManager | Apple Developer Documentation
A convenient interface to the contents of the file system, and the primary means of interacting with it.
developer.apple.com
'iOS' 카테고리의 다른 글
iOS 테이블셀 원하는 색이 안나오는경우 (0) | 2024.04.25 |
---|---|
present로 다른 뷰로 이동후 돌아올때, viewWillApear 메서드가 호출되지않는점 (0) | 2024.04.22 |
Delegate 패턴 구현중에 delgate = nil 오류 (0) | 2024.04.22 |
SQLite3에 대하여 Swift (0) | 2024.04.13 |
iOS 레이아웃 이해하기 (1) | 2024.04.06 |