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 回答