NSTask in Objective-C - objective-c

So I'm trying to run some terminal commands from my program, and I am getting some confusing errors.
Im a newer developer coming from Java, so I may be missing something.
Heres the code:
NSTask *task = [[NSTask alloc] init];
NSString *commitText = [commitMessage stringValue];
NSString *a = [NSString stringWithFormat:#"cd %#", dirPath];
NSString *c = [NSString stringWithFormat:#"git commit -m '%#'", commitText];
NSArray *commands = [[NSArray alloc]initWithObjects:a,
#"git add 'Project'",
c,
#"git push origin HEAD",
nil];
[task setLaunchPath:#"/bin/sh"];
// Do commands
NSArray *args = [NSArray arrayWithObjects:commands,
nil];
[task setArguments: args];
[task launch];
And here are the errors:
2012-06-09 08:35:20.561 Auto Git[5433:403] -[__NSArrayI fileSystemRepresentation]: unrecognized selector sent to instance 0x7fb250d6a1e0
2012-06-09 08:35:20.561 Auto Git[5433:403] -[__NSArrayI fileSystemRepresentation]: unrecognized selector sent to instance 0x7fb250d6a1e0
2012-06-09 08:35:20.679 Auto Git[5433:403] (
0 CoreFoundation 0x00007fff870b4f56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90e35d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff871411be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff870a1e23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff870a1c38 _CF_forwarding_prep_0 + 232
5 Foundation 0x00007fff9174f3a3 -[NSConcreteTask launchWithDictionary:] + 901
6 Auto Git 0x000000010d83c6db -[Push push:] + 571
7 CoreFoundation 0x00007fff870a470d -[NSObject performSelector:withObject:] + 61
8 AppKit 0x00007fff8e0f8f7e -[NSApplication sendAction:to:from:] + 139
9 AppKit 0x00007fff8e0f8eb2 -[NSControl sendAction:to:] + 88
10 AppKit 0x00007fff8e0f8ddd -[NSCell _sendActionFrom:] + 137
11 AppKit 0x00007fff8e0f82a0 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
12 AppKit 0x00007fff8e177fc4 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
13 AppKit 0x00007fff8e0f6eaa -[NSControl mouseDown:] + 786
14 AppKit 0x00007fff8e0c2348 -[NSWindow sendEvent:] + 6306
15 AppKit 0x00007fff8e05ba55 -[NSApplication sendEvent:] + 5593
16 AppKit 0x00007fff8dff20c6 -[NSApplication run] + 555
17 AppKit 0x00007fff8e26e244 NSApplicationMain + 867
18 Auto Git 0x000000010d83bff2 main + 34
19 Auto Git 0x000000010d83bfc4 start + 52
20 ??? 0x0000000000000003 0x0 + 3
)
Thanks!

Your arguments array contains an array. It should be an array of strings. Use your commands object as that parameter for NSTask.

I think the problem is that your passing a array with a array of strings to setArguments. You should pass an array with strings only not an nested array.
But I think you misunderstand how the arguments to NSTask works. You should probably do something like this:
[task setArguments:[[[NSArray alloc] initWithObjects:
#"git", #"add", #"Project", nil]
autorelease]];
Etc, or if you really want to use sh you probably need to add some ; to separate the shell commands.

Related

Trying to make this work... (Xcode for mac NOT iPhone) - ArrayController

I'm writing a stopwatch application for mac, and am currently working on the 'laps' feature. I am putting the laps into a Table View for better organization. I'm using an Array Controller to put things into the table.
Basically, what I'm trying to do is this:
[arrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Lap 1",
#"lapNumber", nil]];
That works fine and dandy, but I'd like to be able to control that number next to lap using an integer representing the number of laps, called numLaps. Thus, my code would be:
[arrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Lap %i",
numLaps, #"lapNumber", nil]];
However, as that is more than two commas before the nil, I think the program is getting screwed up. I am getting the following thrown in the console, though I don't exactly understand what it means / how to fix it:
2013-09-03 16:52:31.515 Popup[3242:303] +[NSMutableDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?
2013-09-03 16:52:31.519 Popup[3242:303] (
0 CoreFoundation 0x00007fff9800a0a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9920b3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff97fe8e31 +[NSDictionary dictionaryWithObjectsAndKeys:] + 433
3 Popup 0x00000001000035a0 -[PanelController btnLapWasClicked:] + 192
4 AppKit 0x00007fff96082a59 -[NSApplication sendAction:to:from:] + 342
5 AppKit 0x00007fff960828b7 -[NSControl sendAction:to:] + 85
6 AppKit 0x00007fff960827eb -[NSCell _sendActionFrom:] + 138
7 AppKit 0x00007fff96080cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
8 AppKit 0x00007fff96080521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
9 AppKit 0x00007fff9607fc9c -[NSControl mouseDown:] + 820
10 AppKit 0x00007fff9607760e -[NSWindow sendEvent:] + 6853
11 AppKit 0x00007fff96073744 -[NSApplication sendEvent:] + 5761
12 AppKit 0x00007fff95f892fa -[NSApplication run] + 636
13 AppKit 0x00007fff95f2dcb6 NSApplicationMain + 869
14 Popup 0x0000000100001652 main + 34
15 Popup 0x0000000100001624 start + 52
)
Any ideas how to implement what I'm trying to do in another fashion that won't confuse the program?
Thanks.
You should use the modern obj-c notation. That enables you to create dictionaries and arrays in a more natural way.
NSDictionary *dic = #{#"Laps ": #(numLaps), #"someotherkey":#"anditswalue"};
In the code you show the keys and values are not in pairs. You must always insert pairs. (For detailed reference see the NSDictionary documentation.)
NSString *key = #"laps";
NSString *value = [NSStringWithFormat:#"Lap %i", numLaps];
[arrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:
value, key, nil]];
Also, you need to think over what you want to store in the dictionary. The keys and values are not apparent in your example.

showing elements of dictionary

I have a plist file that contains array of dictionaries, and I'm trying to show in console the elements of the dictionnaries... here is my code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"validrep" ofType:#"plist"];
descArray = [[NSMutableArray alloc] init];
NSString *key = [NSString stringWithFormat:#"test %i",i+1];
NSMutableArray *tabreponses = [[NSMutableArray arrayWithContentsOfFile:path] retain];
NSDictionary *dictreponses = [NSDictionary dictionaryWithObject:[tabreponses objectAtIndex:i] forKey:key];
[descArray addObject:dictreponses];
NSDictionary *dictionary = [descArray objectAtIndex:i];
NSArray *array = [dictionary objectForKey:key];
NSLog(#"the array is %#, it contains %i elements.",array,[array count]);
Till now everythig is working correctly and this is what the console is showing:
2011-12-14 14:52:33.845 Daltonien[1459:b603] the array is {
rep1 = "1 \U00e9toile derri\U00e8re un quadrillage ";
rep2 = "1 lettre B derri\U00e8re un quadrillage";
rep3 = "1 quadrillage seul ";
}, it contains 3 elements.
but it doesn't work when i try to show the first element of the array, i do it like this:
NSLog(#"the array is %#, it contains %i elements, the first element is %# .",array,[array count],[array objectAtIndex:i]);
This results in an exception:
Daltonien[1478:b603] -[__NSCFDictionary objectAtIndex:]:
unrecognized selector sent to instance 0x4b8cbd0
Daltonien[1478:b603] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFDictionary objectAtIndex:]:
unrecognized selector sent to instance 0x4b8cbd0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dca5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1e313 objc_exception_throw + 44
2 CoreFoundation 0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3b966 ___forwarding___ + 966
4 CoreFoundation 0x00d3b522 _CF_forwarding_prep_0 + 50
5 Daltonien 0x00002cff -[DetailViewController tableView:numberOfRowsInSection:] + 193
6 UIKit 0x004772b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
7 UIKit 0x00474d88 -[UITableViewRowData numberOfRows] + 108
8 UIKit 0x00328677 -[UITableView noteNumberOfRowsChanged] + 132
9 UIKit 0x00335708 -[UITableView reloadData] + 773
10 UIKit 0x00332844 -[UITableView layoutSubviews] + 42
11 QuartzCore 0x01d6aa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d6cddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d120b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d13294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d1346d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00dab89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d406e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d091d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d08840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d08761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017211c4 GSEventRunModal + 217
22 GraphicsServices 0x01721289 GSEventRun + 115
23 UIKit 0x002c8c93 UIApplicationMain + 1160
24 Daltonien 0x000020c8 main + 102
25 Daltonien 0x00002059 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception
with what should i change objectAtIndex:i
THANX for helping me.
The problem is this:
Your key, #"test1", is actually a dictionary, not an array...
To get the first key / value of the dictionary, you would do the following
[[myDictionary keys] objectAtIndex:0]
[[myDictionary values] objectAtIndex:0]
If you want the first object in your array, you'll want something like this:
[array objectAtIndex:0];
To loop through all of the objects, this will do it:
for (id someObject in array) {
// Do stuff
}

SIGABRT while adding objects to an NSMutableArray

I have a method which returns an NSArray with points to be plotted. Following is the code for my method.
- (NSArray *)pointsToPlot:(GraphView *)requester
{
NSMutableArray *points = [[NSSet alloc] init];
CGPoint midPoint;
midPoint.x = self.graph.bounds.origin.x + self.graph.bounds.size.width / 2;
midPoint.y = self.graph.bounds.origin.y + self.graph.bounds.size.height / 2;
//Find points to plot
NSValue *point1 = [NSValue valueWithCGPoint:CGPointMake(midPoint.x - 10, midPoint.y)];
NSValue *point2 = [NSValue valueWithCGPoint:CGPointMake(midPoint.x, midPoint.y - 10)];
NSValue *point3 = [NSValue valueWithCGPoint:CGPointMake(midPoint.x + 10, midPoint.y)];
[points addObject:point1];
[points addObject:point2];
[points addObject:point3];
[points autorelease];
return points;
}
I am getting SIGABRT as soon as I add point1 to the points array.
Following is the stack trace obtained:
2011-10-27 10:43:36.939 Graphing Calculator[7056:207] -[__NSSet0 addObject:]: unrecognized selector sent to instance 0x4b57900
2011-10-27 10:43:36.943 Graphing Calculator[7056:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSet0 addObject:]: unrecognized selector sent to instance 0x4b57900'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc95a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1d313 objc_exception_throw + 44
2 CoreFoundation 0x00dcb0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3a966 ___forwarding___ + 966
4 CoreFoundation 0x00d3a522 _CF_forwarding_prep_0 + 50
5 Graphing Calculator 0x000073cd -[GraphViewController pointsToPlot:] + 1037
6 Graphing Calculator 0x00006895 -[GraphView drawRect:] + 965
7 UIKit 0x00053187 -[UIView(CALayerDelegate) drawLayer:inContext:] + 426
8 QuartzCore 0x016b3b5e -[CALayer drawInContext:] + 143
9 QuartzCore 0x016bfe47 _ZL16backing_callbackP9CGContextPv + 85
10 QuartzCore 0x0160d1f7 CABackingStoreUpdate + 2246
11 QuartzCore 0x016bfd24 -[CALayer _display] + 1085
12 QuartzCore 0x016b627d CALayerDisplayIfNeeded + 231
13 QuartzCore 0x0165b0c3 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 325
14 QuartzCore 0x0165c294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x0165c46d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00daa89b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d3f6e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d081d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d07840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d07761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x010011c4 GSEventRunModal + 217
22 GraphicsServices 0x01001289 GSEventRun + 115
23 UIKit 0x00029c93 UIApplicationMain + 1160
24 Graphing Calculator 0x000021d9 main + 121
25 Graphing Calculator 0x00002155 start + 53
)
terminate called after throwing an instance of 'NSException'
Could someone please explain me what am I doing wrong here?
Change
NSMutableArray *points = [[NSSet alloc] init];
to
NSMutableArray *points = [[NSMutableArray alloc] init];
You are creating and initializing an NSSet and storing it to a reference for NSMutableArray.
Change the following line:
NSMutableArray *points = [[NSSet alloc] init];
To this line:
NSMutableArray *points = [[NSMutableArray alloc] initWithCapacity:3];

Get iTunes Artwork for Current Song with ScriptingBridge

I have been trying to figure out how to get the iTunes artwork for the currently playing song with scripting bridge. I have gotten to a point where it works for some songs, but for others, I get a SIGABRT. I'm not sure what the issue could be, so any help would be greatly appreciated. Here is what I have so far:
iTunesApplication * iTunes = [SBApplication applicationWithBundleIdentifier:#"com.apple.iTunes"];
NSImage *songArtwork;
iTunesTrack *current = [iTunes currentTrack];
iTunesArtwork *artwork = (iTunesArtwork *)[[[current artworks] get] lastObject];
if(artwork != nil)
songArtwork = [artwork data];
else
songArtwork = [NSImage imageNamed:#"Image.tiff"];
NSMenuItem *artworkMenuItem = [[NSMenuItem alloc] initWithTitle:#"" action:NULL keyEquivalent:#""];
[songArtwork setSize:NSMakeSize(128, 128)];
[artworkMenuItem setImage:songArtwork];
[Menu insertItem:artworkMenuItem atIndex:0];
I for some songs it works, and displays the artwork nicely in the menu item, but for others I get a SIGABRT on the line:
[songArtwork setSize:NSMakeSize(128, 128)];
The output of the console is as follows:
2011-08-12 23:13:20.094 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
2011-08-12 23:13:20.095 SongViewer[2146:707] An uncaught exception was raised
2011-08-12 23:13:20.096 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
2011-08-12 23:13:20.097 SongViewer[2146:707] (
0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
9 AppKit 0x00007fff8d9d01b9 loadNib + 322
10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
14 SongViewer 0x0000000100001882 main + 34
15 SongViewer 0x0000000100001854 start + 52
)
2011-08-12 23:13:20.098 SongViewer[2146:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
9 AppKit 0x00007fff8d9d01b9 loadNib + 322
10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
14 SongViewer 0x0000000100001882 main + 34
15 SongViewer 0x0000000100001854 start + 52
)
terminate called throwing an exception(gdb)
If anyone has any idea what could be wrong, please let me know!!
Ok so I figured it out. The solution is to use the NSData raw data provided by the API rather than the NSImage. So I used:
NSImage *songArtwork = [[NSImage alloc] initWithData:[artwork rawData]];
rather than
songArtwork = [artwork data];
I have to fetch batch of track artworks from iTunes and use ‘rawData’ too.
But this way is inefficient.
I found a better way (actually it decreases ‘fetch’ time about 2 times, it’s very significant when fetching artworks for many tracks using ‘valueForKey:’ according to «Improving the Performance of Scripting Bridge Code»).
So I decided to understand what’s wrong with iTunesArtwork ‘data’ property.
We expect to get an NSImage object (according to iTunes.h ), but real object is kind of ‘NSAppleEventDescriptor’. And it’s easy to guess, that this object contains an image for us. So we can just use ‘data’ property to get image data. And this is really faster than getting ‘rawData’ from iTunesArtwork.
But sometimes iTunes return NSImage object instead NSAppleEventDescriptor. This is an strange behavior, but it's still faster then using rawData.

core data strange unrecognized selector sent to instance

Dear community. I try to pickup some data from managed object context in main AppDelegate from other thread.
NSError *error = nil;
AppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
NSFetchRequest *requestCodesList = [[[NSFetchRequest alloc] init] autorelease];
[requestCodesList setEntity:[NSEntityDescription entityForName:#"CodesvsDestinationsList"
inManagedObjectContext:[appDelegate managedObjectContext]]];
[requestCodesList setPredicate:[NSPredicate predicateWithFormat:#"(%K.carrier.name == %#) AND (%K.prefix == %#) AND (code == %#) AND (originalCode == %#)",
destinationTypeRelationShipName,
carrierName,
destinationTypeRelationShipName,
prefix,
[destinationParameters valueForKey:#"code"],
[destinationParameters valueForKey:#"originalCode"]]];
//[destinationParameters valueForKey:#"originalCode"]]];
NSLog(#" Predicate is:%# START",requestCodesList);
NSArray *codesInLocalSystem = [[appDelegate managedObjectContext] executeFetchRequest:requestCodesList error:&error];
I just read information from main MOC, so, it's can't be a thread-safe trouble, bcs i don't write nothing there. The problem is start just sometime. Here is what i receive as error:
2010-12-16 12:55:05.162 snow[53293:3a0b] -[NSManagedObject isTemporaryID]: unrecognized selector sent to instance 0x11836db00
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff84cb47b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff87ec40f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff84d0e110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff84c8691f ___forwarding___ + 751
4 CoreFoundation 0x00007fff84c82a68 _CF_forwarding_prep_0 + 232
5 CoreData 0x00007fff85374341 getValueCore + 33
6 CoreData 0x00007fff853742e4 _PFCMT_GetValue + 20
7 CoreData 0x00007fff8537422d -[NSManagedObjectContext(_NSInternalAdditions) _retainedObjectWithID:optionalHandler:withInlineStorage:] + 45
8 CoreData 0x00007fff85376edd _PF_FulfillDeferredFault + 541
9 CoreData 0x00007fff8537aab7 _sharedIMPL_pvfk_core + 87
10 CoreData 0x00007fff8537ac28 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _genericValueForKey:withIndex:flags:] + 40
11 CoreData 0x00007fff853804be -[NSManagedObject valueForKey:] + 270
12 Foundation 0x00007fff854b9f6f -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 357
13 Foundation 0x00007fff854b9f82 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 376
14 Foundation 0x00007fff8551ca22 -[NSFunctionExpression expressionValueWithObject:context:] + 530
15 Foundation 0x00007fff854e03a7 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 223
16 Foundation 0x00007fff8551c7ba -[NSCompoundPredicateOperator evaluatePredicates:withObject:substitutionVariables:] + 235
17 Foundation 0x00007fff8551c690 -[NSCompoundPredicate evaluateWithObject:substitutionVariables:] + 265
18 CoreData 0x00007fff85364e41 -[NSManagedObjectContext executeFetchRequest:error:] + 1361
19 snow 0x0000000100014a5e -[AppController externalDestinationsForCodeIsAlresdyInLocalDatabaseForCarrierName:withEnabledState:withDestinationParameters:withDestinationTypeRelationShipName:withPrefix:withExternalRateNumber:withAddedDestinations:withCheckForLocalAddedDestinations:] + 862
20 snow 0x00000001000158aa -[AppController updateDestinationListforCarrier:destinationType:] + 2586
21 snow 0x0000000100015d72 -[AppController makeUpdatesForCarrier:andTypeOfOperation:forDirection:] + 754
22 snow 0x00000001000160a1 -[AppController main] + 689
23 Foundation 0x00007fff854d3de4 -[__NSOperationInternal start] + 681
24 Foundation 0x00007fff855b2beb __doStart2 + 97
25 libSystem.B.dylib 0x00007fff84f452c4 _dispatch_call_block_and_release + 15
26 libSystem.B.dylib 0x00007fff84f23831 _dispatch_worker_thread2 + 239
27 libSystem.B.dylib 0x00007fff84f23168 _pthread_wqthread + 353
28 libSystem.B.dylib 0x00007fff84f23005 start_wqthread + 13
)
terminate called after throwing an instance of 'NSException'
For the sake of anybody else running into this - it's likely that you're passing an NSManagedObject subclass to a method that wants an NSManagedObjectID. Check that your method signatures line up between .h and .m files.
It may not be the actual source of your problem; but ManagedObjectContexts are intended to used one per thread. If you want to access Core Data objects you have to use a separate context for each thread and pass IDs between them.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html
I got this issue by passing in the wrong ID to existingObjectWithID:error:. I was passing in the object's id when I should have used objectID.