I need to add persistency to an NSOperationQueue, so the user can close my application without lose any data.
I’m a big fan of core data, so I’m looking for a way to store my NSOperation subclass on core data.
Any advice?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure about your question but I’ll try to give you some hints.
Yes, Core Data could be a valid approach to do it. I don’t know the reason why you need to store a
NSOperation.What I can suggest, instead, is to arrange your model to deal with syncing operations. In particular, I would add an attribute to the entities you need to sync with your sever. Call it , for example,
isSyncand say it’s aBOOLvalue.So, when a specific data is synced with server and you have received a good response, you could just modify that attribute to assume the
YESvalue. This means that a specific data has been synced. In other words, when an object (data) is not synced, itsisSyncvalue isNO, otherwise isYESand, if you want, you can delete it.The next time, you can sync data that have
isSyncvalue toNO. They have not been synced yet. Other elements are already synced and you can delete them to save space on your device.To have an understanding on how syncing can be done, I really suggest to read this stackoverflow topic How to Sync iPhone Core Data with web server, and then push to other devices?.
Furthermore, if you deal with operations, you need to cancel current operations if the user has closed the app. A really interesting discussion can be found in Queue of NSOperations and handling application exit.
Obviously there could be other solutions to achieve this, but I think it could be a simply way to achieve what you want to do.
Hope that helps.