Core data 离开IBAction后获取执行错误访问

Core data 离开IBAction后获取执行错误访问,core-data,exc-bad-access,ibaction,Core Data,Exc Bad Access,Ibaction,我正试图从一个包含核心数据的SQLlite数据库中获取信息,在离开从DB获取NSManageObject的iAction之后,应用程序崩溃,只出现了一个EXEC\u BAD\u访问错误 执行的代码是: - (IBAction)abrir:(id)sender{ [openBrowser setTag:[sender tag]]; [self showOpenPanel:mWindow]; if (acceptCancelButton) { NSString *auxN; NSPr

我正试图从一个包含核心数据的SQLlite数据库中获取信息,在离开从DB获取NSManageObject的iAction之后,应用程序崩溃,只出现了一个EXEC\u BAD\u访问错误

执行的代码是:

- (IBAction)abrir:(id)sender{
[openBrowser setTag:[sender tag]];
[self showOpenPanel:mWindow];
if (acceptCancelButton) {
    NSString *auxN;
    NSPredicate *auxP;
    NSFetchRequest *auxFR;
    NSError *err;
    NSArray *array;
    switch ([sender tag]) {
        case 1:
            auxN = [[[openBrowser selectedCell] stringValue] copy];
            auxP =[NSPredicate predicateWithFormat:@"studyName == %@", auxN];
            auxFR = [[NSFetchRequest alloc] init];
            [auxFR setPredicate:auxP];
            [auxFR setEntity:[NSEntityDescription entityForName:@"Study" inManagedObjectContext:managedObjectContext]];
            [auxFR setIncludesSubentities:NO];
            [auxFR setFetchLimit:1];
            array = [managedObjectContext executeFetchRequest:auxFR error:&err];
            if(array){
                /*
                 Instanciamos un nuevo nsmanagedobject y lo cargamos con la información
                 leida de la BD
                 */
                actualStudy = [NSEntityDescription insertNewObjectForEntityForName:@"Study" inManagedObjectContext:managedObjectContext];
                [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyName"] forKey:@"studyName"];
                [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyPath"] forKey:@"studyPath"];
                [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyDescription"] forKey:@"studyDescription"];
                [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"compressRate"] forKey:@"compressRate"];
                [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"testDuration"] forKey:@"testDuration"];
                NSLog(@"%@ %@ %@ %d %d", 
                      [actualStudy valueForKey:@"studyName"],
                      [actualStudy valueForKey:@"studyPath"],
                      [actualStudy valueForKey:@"studyDescription"],
                      [[actualStudy valueForKey:@"compressRate"] floatValue],
                      [[actualStudy valueForKey:@"testDuration"] intValue]);
            }else{
                [Auxiliar showError:-15];
            }
            break;
        ...
    }
}
}

  • actualStudy是@interface Study的一个变量:NSManagedObject{
代码正常执行,但当应用程序从呼叫返回时,会显示以下消息:

The Debugger has exited with status 0.
[Session started at 2016-03-16 15:23:07 +0000.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
tty /dev/ttys001
Loading program into debugger…
sharedlibrary apply-load-rules all
warning: Unable to read symbols from "CoreData" (not yet mapped into memory).
Program loaded.
run
[Switching to process 3574]
Running…
[Switching to process 3574]
[Switching to process 3574]
[Switching to process 3574]
[Switching to process 3574]
(gdb) continue
Current language:  auto; currently objective-c++
(gdb) continue
2016-03-16 15:23:36.720 eTracker[3574:a0f] CoreData /Users/admin/usabilimac/build/Debug/CoreData/ Prueba core data 600 0
Program received signal:  “EXC_BAD_ACCESS”.
(gdb)
行政人员应:

#0  0x7fff88de6f10 in objc_msgSend
#1  0x7fff836101d6 in _CFAutoreleasePoolPop
#2  0x7fff86d3e110 in -[NSAutoreleasePool drain]
#3  0x7fff81e27723 in -[NSApplication run]
#4  0x7fff81e203b0 in NSApplicationMain
#5  0x1000027f1 in main at main.mm:13

问题出在代码的其他部分,但正如我所说的,这是同一数组的多次释放

消除所有显式释放调用后,EXEC\u BAD\u访问消失


感谢所有试图回答我问题的人。

我刚刚发现问题在于managedobjectcontext通过数组调用一个版本,而当离开iAction时,另一个版本会发送到数组对象。我如何避免这种情况?