简体   繁体   中英

iOS can I implement “Save Game” functionality using NSUserDefaults?

I'm looking at this question about how to store custom objects in NSUserDefaults , and am interested if there's something about speed or size limit of NSUserDefaults that would prevent me from storing my single save game file in user defaults?

For example:

I'm thinking of storing: up to 112 entities, each one can have an "inventory" of up to 17 items, a general inventory of up to 512 items. This will either be serialized/decoded or wrapped in a JSON string.

Let's say the whole data size is 5 Mb - can I store this much in user defaults? Will there be a long delay when storing/writing this much info into user defaults?

Of course I can implement a core data stack, but it seems like a bit of an overkill to do this for a single savegame.

Apple not recommend to store large data in preferences. One example why is storing preferences in iCloud to synchronize preferences on all devices.

See following link

In section "Strategies for Using the iCloud Key-Value Store" you can find following:

Each app is limited to 1 MB of total space in the key-value store. (There is also a separate per-key limit of 1 MB and a maximum of 1024 keys are allowed.) Thus, you cannot use the key-value store to share large amounts of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM