nssortdescriptor

Sorting by date format in iphone

喜欢而已 提交于 2019-12-12 01:33:50
问题 I am new to iphone development.I am sorting a mutable array with respect to date.But it is sorting Using the date parameter consider it as string.I want to sort it by date.How can i achieve that .Please help me out. NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:YES]; [stories sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; Can i use selectors? if so how should i use it?.Thanks. 回答1: -(void)parser:(NSXMLParser *)parser

Using KVC in NSSortDescriptor

喜你入骨 提交于 2019-12-11 18:09:38
问题 I need to sort a bunch of objects based on an integer that is stored in an NSString . I know this is one solution and it works: NSSortDescriptor *mySortDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"from" ascending: YES comparator:^(id obj1, id obj2) { if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult) NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult) NSOrderedAscending; } return (NSComparisonResult)

NSFetchResultsController + sectionNameKeyPath + section order

不羁的心 提交于 2019-12-11 17:35:59
问题 I have a one to many entity relationship between two entities: EntityP (Parent) <-->> EntityC (Child) Attributes and Relationships: EntityP.title EntityP.dateTimeStamp EntityP.PtoC (relationship) EntityC.title EntityC.dateTimeStamp EntityC.CtoP (relationship) // Can be used to get "one" EntityP record I use fetch results controller to show the results. Here's my implementation of the fetch results controller: #pragma mark - #pragma mark Fetched results controller - (NSFetchedResultsController

Sort NSArray of NSDictionary objects using NSSortDescriptor

耗尽温柔 提交于 2019-12-11 12:39:31
问题 I have an array of dictionaries that contain information about high scores. I am trying to figure out how to sort them by the different values in the dictionaries but cannot get it to work. An example shown below attempts to sort by "Score": NSDictionary *highScoreDictionary1 = @{@"Score" : @52, @"Duration" : @230 , @"Date" : [NSDate date]}; NSDictionary *highScoreDictionary2 = @{@"Score" : @23, @"Duration" : @230 , @"Date" : [NSDate date]}; NSDictionary *highScoreDictionary3 = @{@"Score" :

Add new entries to a table view controller at the top of the table with each new entry

☆樱花仙子☆ 提交于 2019-12-11 05:06:27
问题 I have a working app so far which basically consists of the following: Using Core Data, I have 1 Table View Controller with an Add Button which modally calls up a new View Controller prompting the user to add text into three fields. When the user clicks save, the entry is added to the table view controller as a subtitle cell with the information filled in. It works well. What I am confused about and have been looking for answers is the fact that each new entry gets added to the bottom of the

Using a NSFetchedResultsController with an NSManagedObject and fetched properties

淺唱寂寞╮ 提交于 2019-12-11 02:45:46
问题 I have a database of Card s and Printing s that I have in one store (reference data) and my user's data of Container s and CardInstance s in another store (as Apple suggests). Each user's card is a table CardInstance that contains a specific printingID that corresponds with a specific printing of a card. I'm trying to use a NSFetchedResultsController to filter the values of the cards so that it can manage the groupings and stuff using reusable code. Again, here's the basic overview of the

Sorting an NSArray using another NSArray as a guide

≡放荡痞女 提交于 2019-12-10 17:44:02
问题 So, imagine you have a couple of arrays, Colors and Shapes, like this: Colors: { Yellow, Blue, Red } Shapes: { Square, Circle, Diamond } Now, if I want to sort Colors into alphabetical order I can do something like this: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES selector:@selector(localizedCompare:)]; NSArray *sortedColors = [colors sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [sortDescriptor release]; But how would I

NSSortDescriptor with a function

ⅰ亾dé卋堺 提交于 2019-12-10 16:27:40
问题 I only have a limited experience in using NSSortDescriptor. It was sorting on one key and it worked fine. But here is what I need now, I have a set of pairs of numbers, for example : {(2,3), (44,5), (6,17), (33,7) ……(173,21)} I want to sort the pairs (x,y) according to the value of a given function myfunction(x,y). There is the trivial idea of making triplets (x,y,z) where z would be the computation of myfunction(x,y) and then sort the set of triplets, but this not what I want. Is there a

Problem with NSSortDescriptor using custom comparator via selector

主宰稳场 提交于 2019-12-10 12:45:34
问题 I want to use a sortdescriptor with a custom comparator NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"object.dateTime" ascending:YES selector:@selector(compareObject:toObject:)]; (the key is a ManagedObject) Comparator method: - (NSComparisonResult)compareObject:(id)date1 toObject:(id)date2 { NSComparisonResult comparisonResult; // Complex comparator contents return comparisonResult; } However, I get an error: 'NSInvalidArgumentException ', reason: '-[__NSDate

Sort NSArray by date and time

空扰寡人 提交于 2019-12-10 12:04:50
问题 This may be a duplicate question, but i have a strange issue, So that i have pasted it on stack. I have a issue while sorting NSArray by date and time. For example, I have below fields in Database file:- id Name Date 1 ABC 2015-01-29 16:36:31 2 AAA 2015-01-29 16:36:31 3 BBB 2015-01-29 16:36:31 4 CCC 2015-01-29 16:36:31 5 DDD 2015-01-29 16:36:31 Note :- Datatype of Date filed is Timestamp in sqlite Database and i am storing it as NSDate while fetching data. Now, I am sorting this data as below