-
Notifications
You must be signed in to change notification settings - Fork 0
UserDefaults size error
공식 문서 상에서는 tvOS를 제외하고는 UserDefaults에 저장할 수 있는 데이터 size의 limit는 없다고 한다.
Currently, there is only a size limit for data stored to local user defaults on tvOS, which posts a warning notification when user defaults storage reaches 512kB in size, and terminates apps when user defaults storage reaches 1MB in size.
그래서 안심하고 데모용으로 프로필 이미지를 UserDefaults에 저장하고 있었는데
아래와 같은 에러가 발생했다.

4194304면 딱 4MB인데, 왜 이러는 걸까?
찾아보니 포럼에서도 이미 관련된 이슈에 대해 이야기를 나눈 게 있어서 살펴봤다.
[iOS13で密かに追加されたUserDefaultsへの保存制限 - Takahiro Octopress Blog](https://grandbig.github.io/blog/2019/10/19/ios13-userdefaults/)
저 글을 살펴보면 4MB를 약간 넘는 수준은 저장해주고 완전히 범위를 넘어간 데이터는 저장되지 않는다고 한다.
소개한 글에서는 데이터가 유실된다고는 하는데, 실제로 우리 서비스에서 테스트할 때는 저장은 됐다.
저장 여부는 테스트 환경마다 다른 부분이 있는 듯 싶다. 이 부분은 더 찾아봐야겠다.
안정성을 위해서 큰 데이터 저장은 UserDefaults 대신 CoreData, FileManager를 활용하는 게 좋겠다.
[sizeLimitExceededNotification | Apple Developer Documentation](https://developer.apple.com/documentation/foundation/userdefaults/1617187-sizelimitexceedednotification)
[iOS 13 - Attempting to store >=… | Apple Developer Forums](https://developer.apple.com/forums/thread/121527)
NI, MPC
리팩토링/리디자인
테스트
Supabase
- 배현진
- 윤지성
- 최진원
- 허혜민