objective c - Fetch the smallest date of an object in CoreData -


I am facing the same problem, but @Deidelong's answer is not working for me

To get a small date in the set of objects, I get the following error

  - [NSDT count]: An unspecified selector was sent for example  

>

My understanding is that NSExpression 's max: support only NSArray s so I need another solution.

@Deidelong suggested to use the ascending nssort descriptor , and I did this:

  NSFetchRequest * fetchRequest = [[NSFetchRequest alloc ] Init]; FetchRequest.entity = [NSEntityDescription EntityForName: Managed object contexts in NSStringFromClass ([GCSession class]): self.objectContext]; FetchRequest.fetchLimit = 1; NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey: @ "startDate" ascending: yes]; FetchRequest.sortDescriptors = [NSArray arrayWithObject: sort]; GCSession * session = [[self.objectContext executeFetchRequest: fetchRequest error: zero] lastObject]; Return Session Start; The problem here is that the  session  returned from Fetcher does not appear with the smallest  start date . In my tests, it seems that it has also returned the  latest  date but it does not seem to consistently.  

I also sort every GCSession object and sort it but it seems that in the above manner, especially the GCSession number will increase when the user app Will use.

edit : bug in example code of apple

After the object is brought in only one way it comes in the game you set a fetch limit of one And there is no prediction that "move any random single GCSession object". An array 1 element is long to fetch one, then it changes it, which is useless.

If you want to use a type to find a minimum or maximum, then you have to get all the items and then sort them into them. Removing the line:

  fetchRequest.fetchLimit = 1;   

one ?? | The code should be allowed to work

However, you should be able to get the minimum and maximum value with expressions. This is a basic operation.

EDIT: Look at the comments for more details but the example of the applet can work if you change the backing store to SQL instead of XML

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -