Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

how to get "Newest Record" when fetching record #337

Closed
vanbungkring opened this Issue Dec 11, 2012 · 5 comments

Comments

Projects
None yet
3 participants

as title. how to get newest record when fetching records?

for example:
first iteration i save "Singapore" with object name Country,
second iteration i save "USA" with object name Country,

now when i fetch it

SomeDatabase *Country = [SomeDatabase MR_findFirst];

NSLog(@"Country Name---->%@",Country.Name); i get Singapore,

i want get the last inserted to coredata, that supposed to be "USA",,,

many thanks to answer this question

@ghost ghost assigned tonyarnold Dec 14, 2012

Contributor

tonyarnold commented Dec 14, 2012

Hi @vanbungkring — Core Data doesn't really have any idea which record was created at what time. If that's important to your app/data, you'll need to add a Date attribute named createdAt (or something similar) to your Country object.

You can then use this createdAt attribute to sort your entries, and retrieve the youngest object.

Does that make sense?

so i've solved this problems thanks tony,, :)

Contributor

tonyarnold commented Dec 14, 2012

No problems — thanks for letting me know!

@tonyarnold tonyarnold closed this Dec 14, 2012

or you can insert to array, and do sorting array :)

Owner

casademora commented Dec 14, 2012

This ticket was answered on stackoverflow:

http://stackoverflow.com/questions/13821534/how-to-get-newest-record-when-fetching-record-with-magical-record

On Dec 14, 2012, at 5:30 AM, Arie notifications@github.com wrote:

or you can insert to array, and do sorting array :)


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment