nssortdescriptor

How to use sortDescriptor for an attribute on a to many relationship

ぃ、小莉子 提交于 2019-12-21 18:57:34
问题 I have a Song Entity and a Playlist Entity. Playlist can have multiple Songs and Songs can be linked to multiple Playlist. I have a ListToSongs Entity which maintains the order in which Songs were added to the Playlist. I am not using "Ordered Relationship" in ios5 (I am aware of its existence and I need more control over my model) and I store the order by a "sortOrder" field in PlayListToSong entity. So the schema is modeled as (relationship names are written in parentheses below): Song

NSSortDescriptor: Custom comparison on multiple keys simultaneously

那年仲夏 提交于 2019-12-21 17:53:29
问题 I have an custom object which contains time period based information, for instance the attributes endCalYear, endMonth and periodLength which indicate the end of each period and its length. I would like to create an NSSortDescriptor based or other sorting method which combines these three attributes and allows sorting this object on all three keys at the same time. Example: EndCalYear endMonth periodLength (months) sortOrder 2012 6 6 1 2012 6 3 2 2012 3 3 3 2011 12 12 4 The sort algorithm

NSSortDescriptor - push # and numbers to the end of the list - iphone xcode

泪湿孤枕 提交于 2019-12-21 11:26:11
问题 I have a table view that shows contacts sorted by alphabetic ordering and divide it to sections. i am using - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[dataSource keyName] ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; then for contacts without name i am using # sign as their first letter so all of them will be grouped in one group. everything is great. the only thing i want is to push the # section to the end

iOS Get objects from CoreData sorted by primary key

让人想犯罪 __ 提交于 2019-12-20 03:17:34
问题 I have saved data into db using CoreData. I need to fetch data from my table in same order that it was saved. Inside table it is ordered by Z_PK - hidded CoreData key. How can I create such sort descriptor. If I use fetch request without sort descriptors my data objects have wrong order. 回答1: Anything not exposed to you by the Core Data framework is an implementation detail. The fact that Z_PK exists, and currently suits your purposes, cannot be relied upon. If creation/save order is

Sort NSFetchedResultsController result based on array?

守給你的承諾、 提交于 2019-12-20 01:55:08
问题 I would like to construct a NSPredicate or NSSortDescriptor (Core Data search) that is based on the content of an array. The array will consists of userId:s in the right order: [1, 2, 5, 3]; I would like to present the result for my NSFetchedResultsController in the same order. So I will: Get the right users (I have done this) Sort the list of users based on my sorted array with userId s. Is this possible to do, and how can I do it? 回答1: I think that is not possible. Sorting the results of a

NSSortdescriptor ineffective on fetch result from NSManagedContext

放肆的年华 提交于 2019-12-19 21:16:52
问题 I'm trying to sort my NSFetchRequest result using a NSSortdescriptor using a key pointing to a NSDate value. My fetch results come out totally random for no clear reason. The NSManagedObjectContext I'm using is updated with a save from a nested child context created on a subclass of NSOperation. I know all this is done successfully because I can get all the data needed from the parent (main) context. Fetching from it just wont sort on date! Strange thing is; predicates for selecting the

NSSortDescriptor with arbitrary sorting

萝らか妹 提交于 2019-12-19 09:04:17
问题 I can't wrap my head around how to do arbitrary sorting with a NSSortDescriptor. I want to do something like this: NSArray *sortAlgorithm = [NSArray arrayWithObjects:@"@", @"#", @"!", @"&", @"r", @"a", nil]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator: ^(id obj1, id obj2) { NSComparisonResult comparisonResult; //Some code that uses sortAlgorithm. return comparisonResult; } ]; This would sort the objects by the key name so that any

NSSortDescriptor on transient attribute for NSFetchedResultsController

纵饮孤独 提交于 2019-12-19 05:49:14
问题 Ok, I initially wanted to make NSSortDescriptor of a request for NSFetchedResultsController to sort based on the property in my NSManagedObject subclass, but It obviously won't do it, because NSFetchedResultsController is limited to predicates and sort descriptors that work on the fetched entity and its relations, so I decided to create a transient attribute in my data model, synthesis the property for this attribute to ivar in my NSManagedObject subclass, and sort based on it. When running

NSSortDescriptor on transient attribute for NSFetchedResultsController

天大地大妈咪最大 提交于 2019-12-19 05:49:06
问题 Ok, I initially wanted to make NSSortDescriptor of a request for NSFetchedResultsController to sort based on the property in my NSManagedObject subclass, but It obviously won't do it, because NSFetchedResultsController is limited to predicates and sort descriptors that work on the fetched entity and its relations, so I decided to create a transient attribute in my data model, synthesis the property for this attribute to ivar in my NSManagedObject subclass, and sort based on it. When running

How to sort array controller alphabetically with numbers last in objective-c?

心不动则不痛 提交于 2019-12-18 04:25:29
问题 I have an NSArrayController and I would like to sort the contents so that anything with English alphabets are sorted first and then anything with numbers and non English characters are sorted last. For example: A, B , C ... Z, 1 , 2, 3 ... 9, 구, 결, ... Currently I only know how to sort items in alphabetical order. Suggestions? NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; [dataController setSortDescriptors: [NSArray arrayWithObject: sort]]; 回答1: You