I try to make some app with stopwatch featu开发者_开发问答re and having some confusing points. First, what is the proper way to keep state of the stopwatch (start, pause, stop). Should I keep this state in core data ?
Second, I created core data entity with Date property to keep start time. Should I delete this entity each time the stopwatch is reset or keep it in separate record ?
CoreData is very heavy handed for what you want unless you want to keep lots of different records in very specific ways
NSUserDefaults would do fine, they are persistent unless you delete the app
This tutorial is very good. So say if you had your two variables time_started and time_ended, you'd get the time between then and write them into the UserDefaults. If you want to keep a record of multiple entries use a loop that increments a count or index.
Dont have time at the mo to write any code but do that tutorial and you might find that NSUserDefaults is better.
Hope it helps
精彩评论