OneBusAway / onebusaway-ios

OneBusAway for iOS, written in Swift.
Other
94 stars 36 forks source link

Move regions storage from UserDefaults to disk #629

Open ualch9 opened 1 year ago

ualch9 commented 1 year ago

Move regions storage from UserDefaults to disk. Storing regions in a database could be overkill since there are only a handful of infrequently-updated regions.

Currently, regions are stored as encoded objects in UserDefaults. We should use Codable to store OBA-regions in /Library/Application Support and custom regions in /Documents.

Files stored in /Documents in the app's sandbox are synced via iCloud and may be exposed via Files.app, which could be helpful for sharing custom regions.

The currently selected region would continue to be stored in UserDefaults, identified by its RegionIdentifier.

Possible file structure

Library/
  └ Application Support/       ☜ Won't be deleted by clearing cache, but won't be synced via iTunes/iCloud
    └ Regions/
      └ default-regions.json   ☜ This can be refreshed via OBA (not user-generated data)

Documents/
  └ custom-regions/            ☜ Any .json in the directory that can be decoded into a Region object.
    └ region-a.json
    └ region-b.json

Library/Application Support/Regions/default-regions.json is not a copy of regions.json, it's the encoded-JSON of how OBAKitCore.Region.


This change should not require an Internet migration, so we don't need to inform the user.

aaryankotharii commented 9 months ago

apologies I did not put up a message requesting permission. I have solved this issue in PR #714. please have a look. cc @ualch9 @aaronbrethorst