0

私のアプリには、Tripエンティティと対多の関係を持つエンティティSpotあり、旅行とそのスポット リストをバックグラウンド スレッドで読み込む必要があります。デバッグ版では正常に動作しますが、リリース版ではスポット リストが空です。少し調べてみたところ、コンパイラの最適化レベルを に設定しない限り、リリース バージョンでは動作しないことがわかりました-O0。おそらくコンパイラのバグだと思います。

より高い最適化レベルで機能させるための提案はありますか、または最適化されていないアプリをリリースする必要がありますか? ありがとう!

コードは次のとおりです。

メインスレッド

[self performSelectorInBackground:@selector(calcRoute:) withObject:self.trip.objectID];

バックグラウンド スレッド

- (void)calcRoute:(NSManagedObjectID *)tripId
{
    //get trip entity
    CoreDataHelper * helper = nil;  //responsible for init model, persistentStore and context
    TripEntity * t = nil;
    helper = [[CoreDataHelper alloc] initWithAnother:mainThreadHelper];  //only take the resource name and storeURL
    t = (TripEntity *)[helper.context objectWithID:tripId];   //retrieve trip
    if (0 == t.spotList.count) {
        [self performSelectorOnMainThread:@selector(drawRouteFailed) withObject:nil waitUntilDone:FALSE];
        return;   //I got here!
    }
//...
}
4

1 に答える 1

0

最後に、私は問題を解決しました。その理由は、メイン スレッド トリップ エンティティを「使用」したためです。実際のコードは次のとおりです。

- (void)calcRoute:(NSManagedObjectID *)tripId
{
    //get trip entity
    CoreDataHelper * helper = nil;  //responsible for init model, persistentStore and context
    TripEntity * t = nil;
    if (self.backgroundDrow) {  //sometimes I don't need background drawing
        helper = [[CoreDataHelper alloc] initWithAnother:mainThreadHelper];  //only take the resource name and storeURL
        t = (TripEntity *)[helper.context objectWithID:tripId];   //retrieve trip
    } else
        t = self.mainThreadTrip;         //HERE is the problem!!!
    if (0 == t.spotList.count) {
        [self performSelectorOnMainThread:@selector(drawRouteFailed) withObject:nil waitUntilDone:FALSE];
        return;   //I got here!
    }
    //...
}

コメントt = self.mainThreadTrip;したらバックグラウンドロードOKになりました!

しかし、私はまだポイントを理解していません!本当の理由を誰か教えてくれませんか?どうもありがとう!

于 2012-10-29T03:46:31.960 に答える