2013-09-25 59 views
1

我使用nsexpression進行分組和計數多個屬性。抓取結果工作下的ios 6和iOS 7罰款,但它並不在IOS 5ios 5 setPropertiesToFetch ...不在GROUP BY問題中

*終止應用程序工作,由於未捕獲的異常「NSInvalidArgumentException」,理由是:「SELECT子句中的查詢與GROUP BY組件可以只包含在GROUP BY或聚合函數(的startDateTime是不是在GROUP BY)」 *第一擲調用堆棧命名的屬性: (0x3689022 0x309bcd6 0x13357d9 0x133543e 0x13351f0 0x1334fc3 0x1334619 0x13340b0 0x133345d 0x13312fd 0x138432b 0x13841fc 0x1384051 0x3285951 0x3285e00 0x1383ff5 0x1383e6d 0x13312fd 0x144043f 0x3a55f 0x38fea 0x22c5a1e 0x2430323 0x3a796 0xc961 0x1b01c6 0xc572 0xc42a 0x1b0684 0x215b34 0x19dff2 0x215a8d 0x1b05cd 0xc142 0xf5c5 0x1b0684 0x215b34 0x19dff2 0x215a8d 0x1b05cd 0xd722 0x384b 0x21fc386 0x21fd274 0x220c183 0x220cc38 0x2200634 0x5177ef5 0x365d195 0x35c1ff2 0x35c08da 0x35bfd84 0x35bfc9b 0x21fcc65 0x21fe626 0x29ad 0x2915爲0x1) 終止叫做拋出異常

而且代碼如下:

NSPropertyDescription *propDesc = [properties objectForKey:@"partyId"]; 
NSExpression *partyid   = [NSExpression expressionForKeyPath:@"partyId"]; 
NSExpression *partyIdCount  = [NSExpression expressionForFunction:@"count:" arguments:[NSArray arrayWithObject:partyid]]; 

NSExpressionDescription *countPartyId = [[NSExpressionDescription alloc] init]; 
[countPartyId setExpression:partyIdCount]; 
[countPartyId setExpressionResultType:NSInteger64AttributeType]; 
[countPartyId setName:@"countResultPartyId"]; 

NSExpression *startDateTime = [NSExpression expressionForKeyPath:@"startDateTime"]; 
NSExpression *latestDateTime = [NSExpression expressionForFunction:@"max:" arguments:[NSArray arrayWithObject:startDateTime]]; 
NSExpressionDescription *dateTimePropertyDescription = [[NSExpressionDescription alloc] init]; 
[callDateTimePropertyDescription setExpression:latestDateTime]; 
[callDateTimePropertyDescription setExpressionResultType:NSDateAttributeType]; 
[callDateTimePropertyDescription setName:@"latestDateTime"]; 

NSPropertyDescription *sortDateGroup = [properties objectForKey:@"sortDate"]; 
NSPropertyDescription *userId = [properties objectForKey:@"userId"]; 

[fetchRequest setPropertiesToGroupBy:[NSArray arrayWithObjects:propDesc,sortDateGroup,userId, nil]]; 
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:propDesc,dateTimePropertyDescription, sortDateGroup,userId,countPartyId, nil]]; 
[fetchRequest setResultType:NSDictionaryResultType]; 

它看起來喜歡它也希望我也可以用startDateTime來聚合。但分組不會工作,因爲可能有多個startDateTime,我需要從它的最新「最大」時間。令人驚訝的是,它可以在iOS 6下工作。7 - 是否知道如何完成這個任務?謝謝。

回答

0

expressionForFunction:@"max:"expressionForFunction:@"min:" doenst工作在ios 5.我不得不離開查詢。並做了第二次查詢以獲得max nsdate for ios 5.