मैं प्राप्त करने में कठिनाई और खोज परिणामों के समूहीकरण के लिए कोड निम्नलिखित है:क्या NSFetchRequest गुणों को समूह समूह असंवेदनशील हो सकता है?
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Song"];
[request setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:predicates]];
[request setResultType:NSDictionaryResultType];
[request setSortDescriptors: @[[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES]]];
NSExpression *countExpression = [NSExpression expressionWithFormat:@"count:(SELF)"];
NSExpressionDescription *expressionDescriprion = [[NSExpressionDescription alloc] init];
[expressionDescriprion setName:@"count"];
[expressionDescriprion setExpression:countExpression];
[expressionDescriprion setExpressionResultType:NSInteger64AttributeType];
NSArray *properties = @[@"artistName", @"songName"];
[request setPropertiesToFetch:[properties arrayByAddingObject:expressionDescriprion]];
[request setPropertiesToGroupBy:properties];
self.fetchedItems = [self.managedObjectContext executeFetchRequest:request error:nil];
जो बहुत अच्छा काम करता है, लेकिन मैं जारी करने का सामना करना पड़ा और प्रकार के साथ की stucked, तो मैं इस propertiesToGroupBy बनाने की जरूरत है (संपत्ति प्रकार NSString है *) मामला असंवेदनशील किसी भी तरह। पल मैं उत्पादन निम्नलिखित है:
<_PFArray 0x7fa3e3ed0d90>(
{
artistName = "System of a Down";
count = 44;
songName = "Lonely Day";
},
{
artistName = "System Of A Down";
count = 2;
songName = "Lonely Day";
},
{
artistName = "System of a Down";
count = 4;
songName = "Chop Suey";
}
)
जो सही नहीं है, तो मैं पहले 2 आइटम ही चयन में होने की जरूरत है, क्योंकि यह एक ही कलाकार है।
क्या इसे प्राप्त करने का कोई तरीका है?
मेरे लिए NSExpressionDescription द्वारा समूह करना असंभव प्रतीत होता है। [अनुरोध सेटप्रॉपर्टीज समूह समूह: myExpressions] के बाद; मेरे पास हमेशा 'NSInvalidArgumentException' है, कारण: 'अमान्य कीपैथ अभिव्यक्ति – iiFreeman