0
親愛なるコミュニティ。 私はいくつかの問題を抱えています。コアデータの数字と範囲を減らして比較する必要があります。ここコアデータの最適化fetchrequest
は、コードの最初の部分である:私は最初の述語と一致しなかった場合
NSFetchRequest *requestDestinationWeBuy = [[[NSFetchRequest alloc] init] autorelease];
[requestDestinationWeBuy setEntity:[NSEntityDescription entityForName:@"DestinationsListWeBuy"
inManagedObjectContext:moc]];
NSError *error = nil;
[requestDestinationWeBuy setPredicate:
[NSPredicate predicateWithFormat:
@"carrier.name == %@ and (country == %@) and (specific == %@) and (prefix == %@) and (enabled == YES) and ((rateSheet == %@) OR (rateSheet == %@))",
outCarrierName,
countryStr,
specificStr,
outCarrierPrefixStr,
outCarrierRateSheet,
@"Price table"]];
NSArray *destinationWeBuyList = nil;
//[requestDestinationWeBuy includesSubentities];
[requestDestinationWeBuy setResultType:NSManagedObjectIDResultType];
destinationWeBuyList = [moc executeFetchRequest:requestDestinationWeBuy error:&error];
、私はそれが数字だと再フェッチ要求を送信(符号量の最後の桁をカットする必要が
。 int maxCodeDeep = 8;
if ([codeStr length] < maxCodeDeep) maxCodeDeep = [[NSNumber numberWithUnsignedInt:[codeStr length]] intValue] - 1;
NSRange codeStrRange = NSMakeRange(0,[codeStr length]);
NSString *changedCode = [NSString string];
BOOL huntingWasSuccess = NO;
for (NSUInteger codeDeep = 0; codeDeep < maxCodeDeep;codeDeep++)
{
codeStrRange.length = codeStrRange.length - 1;
changedCode = [codeStr substringWithRange:codeStrRange];
NSFetchRequest *compareCode = [[[NSFetchRequest alloc] init] autorelease];
[compareCode setEntity:[NSEntityDescription entityForName:@"CodesvsDestinationsList"
inManagedObjectContext:moc]];
NSString *codeRelationshipName = @"destinationsListWeBuy";
[compareCode setPredicate:[NSPredicate predicateWithFormat:@"(%K.carrier.name == %@) and ((code == %@) OR (originalCode == %@)) and (%K.prefix == %@) and (enabled == YES) and ((rateSheetID == %@) OR (rateSheetID == %@))",codeRelationshipName, outCarrierName,changedCode,changedCode, codeRelationshipName, outCarrierPrefixStr,outCarrierRateSheetID,@"65535"]];
//[compareCode includesSubentities];
//[compareCode includesPropertyValues];
[compareCode setResultType:NSManagedObjectIDResultType];
NSArray *codeAfterComparing = [moc executeFetchRequest:compareCode error:&error];
if ([codeAfterComparing count] == 0) {
NSLog(@"ROUTING: Compare was unsucceseful with parameters:%@",compareCode);
continue;
}
else {
destinationWeBuy = [[moc objectWithID:[codeAfterComparing lastObject]] valueForKey:codeRelationshipName];
NSLog(@"ROUTING: Compare was succeseful with parameters:%@\n and destination object:%@\n Carrier name is %@ ",compareCode,destinationWeBuy,carrierName);
//destinationWeBuy = [destinationWeBuyObj objectID];
huntingWasSuccess = YES;
break;
}
}
残念ながら、これには時間とプロセッサーのリソースがあります。 最新のWWDCの推奨事項のいくつかは、@countを使用することを提案していますが、私のケースでどのように使用できるのか分かりません。私が見つけたオブジェクトを使ってn個の次の操作と親オブジェクト。
私の仕事の場合に便利な例を提案できますか? – Alex