Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 14, 2010, 01:59 PM   #1
BadWolf13
macrumors 6502
 
Join Date: Dec 2009
Question about Core Data

I've been working with Core Data for a while, and one thing doesn't make much sense to me. Based on the order the data appears in the tableView or Core Data Widget, and based on what I read in the XML file that the program saves to, there doesn't seem to be any ordering to the information. This doesn't make much sense to me, as I would think it'd be better to save and retrieve information in a set order, especially with a database. Is there some way to set an order when my program is saving the objects to a file, and then retrieve them in that same order, or is it just naturally chaotic?
BadWolf13 is offline   0 Reply With Quote
Old Nov 14, 2010, 02:23 PM   #2
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Though I don't really know the answer, here are some things to think about.

There are three commonly accepted ways of storing a binary tree in a flattened list. You could look at your XML file assuming it was originally a binary tree and try to see if the randomness you see is possibly not so random.

Apple has stated that Core Data is as fast as it can be regardless of the underlying store, so even if it isn't a binary tree, I would have to assume that is organized in some way that is efficient to Core Data itself.
jared_kipe is offline   0 Reply With Quote
Old Nov 14, 2010, 03:05 PM   #3
JoshDC
macrumors regular
 
Join Date: Apr 2009
From the Core Data programming guide:

Quote:
Objects in a persistent store are unordered. Typically you should impose order at the controller or view layer, based on an attribute such as creation date. If there is order inherent in your data, you need to explicitly model that.
One of the issues at hand is what is "ordered"? Something that's ordered for one purpose (e.g. creation date) is of no help with something like a name. As such there's not really much point in saving in one order because it has no idea if it's a useful one.

You can index a certain attribute which will speed up certain operations like sorting and equality, but not others such as CONTAINS.

Are you having an issue with performance, or are you just curious? You seem to ask a lot of question regarding Core Data and the programming guide and free WWDC 2010 videos contain a lot of useful information on the topic.
JoshDC is offline   0 Reply With Quote
Old Nov 14, 2010, 03:05 PM   #4
Littleodie914
macrumors 68000
 
Littleodie914's Avatar
 
Join Date: Jun 2004
Location: Rochester, NY
CoreData does NOT sort your data, nor does it make any guarantees as to the order of data in a query. You have to sort the data yourself, or add an "index" NSUInteger field to all of your data objects.

Quote:
"Core Data expects you to define your own sorting with NSSortDescriptors, so you'll have to add your own attribute to track a user-customizable ordering index like that."

http://stackoverflow.com/questions/8.../831847#831847
Quote:
"Core Data notoriously pays no attention to the order of objects."

http://www.timisted.net/blog/archive...ata-drag-drop/
Littleodie914 is offline   0 Reply With Quote
Old Nov 14, 2010, 03:35 PM   #5
BadWolf13
Thread Starter
macrumors 6502
 
Join Date: Dec 2009
Thank you Odie. That's not the answer I was hoping for, but it is an answer.

Josh, this question is directly related to the last core-data issue I posted on here, mainly due to the fact that we never found a solution.
BadWolf13 is offline   0 Reply With Quote
Old Nov 15, 2010, 09:57 AM   #6
knightlie
macrumors 6502a
 
Join Date: Feb 2008
It's quite common for lists of things in computing to be in an unpredictable order, Java collections are one. I've always though that odd, you'd think there would be SOME kind of order, even if it's not that one you expect, but that's the way it goes.

Your code should not assume it's data is going to arrive in a predictable order - what happens if someone fiddles with the data source and changes that order without you realising? Much better for your program to sort the data itself as it requires, either with an ORDER BY clause in SQL or by sorting your Core Data result set when it returns. The code is the much more resilient.
knightlie is offline   0 Reply With Quote
Old Nov 15, 2010, 10:06 AM   #7
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Oooo thats disappointing. I'll have to redeem myself in your other Core Data related thread.
jared_kipe is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Core Data help. Ernie11 iPhone/iPad Programming 4 May 11, 2014 09:46 PM
Question on new Mac Pro - 6 core vs 8 core robsp2000 Mac Pro 1 Dec 19, 2013 11:16 AM
2013 MP 6 core vs 2010 MP 6 core question allupons Mac Pro 20 Oct 26, 2013 01:48 AM
Having an issue passing data between views with Core Data. iJustinCabral iPhone/iPad Programming 0 Jul 15, 2013 10:50 PM
Saving data from custom tablecells core data luke3 iPhone/iPad Programming 0 Jul 14, 2012 07:09 PM

Forum Jump

All times are GMT -5. The time now is 06:26 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC