Reputation: 5106
I want to store only 20 Notifications which include
"Title,Detail and Received Time" fields inside Notifications Table.But,I only found solution for working CoreData
with CRUD some example.But,I am still seeking for working with limitation when user fetch new results from api inside device database.That is where I am stuck.I don't know how to do it using CoreData
because I was beginner at that.
Requirement :
1.Application can only store 20 Records maximum.So,when it reach max length,it will do First-In-Last-Out to Notifications table base on Notifications Received Time.(First Problem)
2.Every time the user do pull to refresh,my app fetch new notification from Web-Backend and replace or overwrite on user device database when it successfully download new notifications like "Push Notification Service App" on App Store.(Second Problem)
I really need a hand to pick up with core data flow which I am stucking at things I am not familiar with.
Any help or guide please?(Posting Sample with .json is appreciated)
Upvotes: 0
Views: 63
Reputation: 119041
Consider using a service, like RestKit or similar, to support your web service interaction. Each record should have a unique identifier supplied by the server so you can find an existing copy and update it instead of needing to delete everything and recreated it.
To trim your data use a fetch request with a fetchOffset
and a sortDescriptors
by date. This allows you to skip the newest 20 items and gives you a list of everything that needs to be deleted. If you're using RestKit you can supply this fetch request in a fetch request block and the deletion will be done for you.
Upvotes: 1