core data strange unrecognized selector sent to instance - objective-c

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.

Related

Data-core NSException

I don't know where is my problem because the entity "Utente" exist.
Error code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101bf0495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016f099e objc_exception_throw + 43
2 CoreData 0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217
3 CoreData 0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30
4 VucmpraJson 0x000000010000514b -[LoginViewController login:] + 4843
5 UIKit 0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80
6 UIKit 0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530
9 UIKit 0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701
10 UIKit 0x00000001002d66e4 -[UIWindow sendEvent:] + 925
11 UIKit 0x00000001002ae29a -[UIApplication sendEvent:] + 211
12 UIKit 0x000000010029baed _UIApplicationHandleEventQueue + 9579
13 CoreFoundation 0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242
15 CoreFoundation 0x0000000101b9b46f __CFRunLoopRun + 767
16 CoreFoundation 0x0000000101b9ad83 CFRunLoopRunSpecific + 467
17 GraphicsServices 0x00000001040d0f04 GSEventRunModal + 161
18 UIKit 0x000000010029de33 UIApplicationMain + 1010
19 VucmpraJson 0x0000000100021d13 main + 115
20 libdyld.dylib 0x00000001025f15fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
#property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
.
.
.
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject * Utente = [NSEntityDescription insertNewObjectForEntityForName:#"Utente" inManagedObjectContext:context];
[Utente setValue: emailText.text forKey:#"email"];
NSError *error;
//[context save:&error];
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
entities: Utente
attributes: email;password
thx to much guys
nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente'
means that your managed object context is nil. Check self.managedObjectContext assignment.
edit
if (! [self managedObjectContext]) {
NSLog(#"You will receive your exception");
} else {
// Insert new entity into specified context
}

How to understand this crash?

Crash report:
0 ??? 0x0 + 0
1 TestPrj -[AppListReader addInstalledApps:] (AppListReader.m:186) + 77516
2 TestPrj -[AppListReader getAppsInstalled] (AppListReader.m:161) + 77320
3 TestPrj -[DetectAppsInstalledService activate:] (DetectAppsInstalledService.m:48) + 197612
4 TestPrj -[BusinessManager handleBG] (BusinessManager.m:762) + 116672
5 TestPrj -[BusinessManager activate:] (BusinessManager.m:208) + 106236
6 TestPrj -[AppDelegate launchViewController:] (AppDelegate.m:338) + 32564
7 TestPrj -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:153) + 27396
8 UIKit <redacted> + 316
9 UIKit <redacted> + 1564
10 UIKit <redacted> + 772
11 UIKit <redacted> + 3316
12 UIKit <redacted> + 104
13 UIKit <redacted> + 672
14 GraphicsServices <redacted> + 676
15 GraphicsServices <redacted> + 48
16 CoreFoundation <redacted> + 56
17 CoreFoundation <redacted> + 444
18 CoreFoundation <redacted> + 1620
19 CoreFoundation CFRunLoopRunSpecific + 452
20 UIKit <redacted> + 784
21 UIKit UIApplicationMain + 1156
22 TestPrj main (main.m:21) + 23548
23 libdyld.dylib <redacted> + 4
Line 186 is:
NSMutableArray *allObjetcsArr = [self getInstalled];
This is implementation:
-(NSMutableArray *)getInstalled
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:#"ApplicationType",#"Any", [self defaultReturnAttributes] ,#"ReturnAttributes",nil];
MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));
NSMutableArray *allObjetcsArr = [[NSMutableArray alloc]initWithArray:[apps allValues]];
return allObjetcsArr;
}
Crash is received via BugSense and I am not able to reproduce it. I think it is related to MobileInstallationLookup framework (which is private api) but I am not sure.
It is not clear for me, why
-(NSMutableArray *)getInstalled
Is not present in stack trace, only ??? 0x0 + 0
My money is on these lines:
MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));
MobileInstallationLookup is obviously a global, but it's not clear why; for example if it's global they why is it being re-assigned in this method and why does the variable start with a capital letter (which is unconventional)?
There is no check to ensure that dlsym() succeeded, and dereferencing a null pointer would cause the crash you are getting.

NSTask in 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.

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
}

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.