본문 바로가기
1 - iOS

[iOS/Swift] Local DB 비교(Core data, SQLite, Realm)

by seonshine-bibi 2022. 12. 7.
반응형

 

 

 

Core Data

https://developer.apple.com/documentation/coredata

 

Apple Developer Documentation

 

developer.apple.com

 

Core Data: iOS 플랫폼 단에서 지원하는 관계형 데이터베이스 라이브러리

객체 형식으로 저장하고 관리할때 사용하기 좋다.

속도가 빠르다는 단점

thread-safe 하지 않다는 단점

@FetchRequest 라는 프로퍼티 래퍼를 사용해서 편하게 쓸 수 있다.

Widget 등을 개발할때 데이터 연동이 아주 편리하다.

 

 

 

 

 

SQLite

https://github.com/stephencelis/SQLite.swift

 

GitHub - stephencelis/SQLite.swift: A type-safe, Swift-language layer over SQLite3.

A type-safe, Swift-language layer over SQLite3. Contribute to stephencelis/SQLite.swift development by creating an account on GitHub.

github.com

https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md

 

GitHub - stephencelis/SQLite.swift: A type-safe, Swift-language layer over SQLite3.

A type-safe, Swift-language layer over SQLite3. Contribute to stephencelis/SQLite.swift development by creating an account on GitHub.

github.com

 

SQLite: 오픈 소스 기반 DB

모바일 로컬에서 많이 사용한다.

안드로이드와 iOS 양쪽에서 사용할 수 있어서 공유할 수도 있다.

가장 많이 사용되기 때문에, 레퍼런스가 많다.

SQL 구현 가능

 

 

 

 

 

Realm

https://github.com/realm/realm-swift

 

GitHub - realm/realm-swift: Realm is a mobile database: a replacement for Core Data & SQLite

Realm is a mobile database: a replacement for Core Data & SQLite - GitHub - realm/realm-swift: Realm is a mobile database: a replacement for Core Data & SQLite

github.com

 

Realm: 최근 많이 사용하는 DB

안드로이드에서도 사용한다.

다른 DB들보다 속도가 빠르다.

observe하여 update를 체크하여 view를 갱신하는 reactive functionality 제공 (Live Objects)

 

 

 

 

 

주변 의견

  • SQLite 무난하다. 많이 사용한다. 안드로이드와 공유 가능하다.
  • Realm 과 Core Data 구현 난이도는 비슷하다. 둘 다 많이 사용한다.
  • 간단한 정보는 UserDefaults 사용하는 것이 깔끔하다.

 

 

 

 

 

 

결론

  • 안전한 선택지로 가장 오래 사용되어온 SQLite 를 사용하기로 결정되었다. (Android와 통일하기 위한 목적으로 기획적으로 결정된 부분)

 

 

 

 

현재 

  • SQLite에서 성능도 성능이지만, reactive functionality 제공이 안되는게 큰 단점이라, Corea data 또는 Realm으로 migration 하기로 하였다.
  • Realm으로 갈 것 같다. 빠르기도 하고, DB observe 기능이 매우 필요해져서... 
  • 누가 SQLite 쓰라고 해도 어쩔 수 없는 이유가 아니면 안쓸 것 같다. 불편하고, 예상보다 레퍼런스도 적다. 질문해도 답변해줄 사람이 별로 없다. 

 

 

 

 

SQLite -> Realm migration 완료하면 후기를 남겨야겠다,,

 

 

 

하단에 읽어보면 좋을 링크를 첨부한다. 

Local DB에 대한 장단점이 요약되어있다. 

 

 

 

 

 

 

https://realm.io/best-ios-database/

 

 

iOS Databases | Choosing the Best iOS Database

This blog covers what features and considerations to make when choosing an iOS database and why Realm is the best choice

realm.io

 

 

반응형