在发布版本中加载CoreData失败

时间:2012-10-27 12:34:09

标签: ios core-data optimization release

我的应用有一个Trip实体与Spot实体有多对多的关系,我需要在后台线程中加载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!
    }
//...
}

1 个答案:

答案 0 :(得分: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;后,后台加载就变好了!

但我仍然不明白这一点!有人会告诉我真正的原因吗?非常感谢!