Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Autosaved object
    primarykey
    data
    text
    <p>In my app I have Singleton object, which should save its state through app launches. So I need to save it somehow.</p> <p>I see only two options: 1) save it on app termination (plus, maybe, going background); 2) save it each time any property changed.</p> <p>First option looks bad, because app can be killed, for example, because of some bug, memory limits or device power-off (low battery). So I expect state won't be saved.</p> <p>Second option needs either manual notifications about each change, or KVO + observing of each property.</p> <p>Seems that I do something wrong here. Maybe, you can give me some advice or there is some well-known pattern (I've tried to google, but found nothing particular).</p> <p><strong>UPDATE:</strong></p> <p>Yes, there is <code>NSUserDefaults</code>, but to improve its usability (smth. more than just key-values) I would write wrapper-methords, so I will end with the same problem (lines of manual coding).</p> <p><strong>UPDATE2:</strong></p> <p><code>CoreData</code> is also bad choice for me: just one object to store + inserting there also needs some more lines of code.</p> <p><strong>UPDATE3:</strong></p> <p>It's not a question about "how to save". It's about "how to call this saving automatically (or with less of coding)". So in <code>NSUserDefault</code> way we need to manually implement each property as wrapper. In <code>NSCoding</code> - call <code>save</code> or post notification (to catch &amp; save from one place) from each property also.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload