Note that there are some explanatory texts on larger screens.

plurals
  1. POCoreData crash while saving after setting value for NSManagedObject's property
    primarykey
    data
    text
    <p>I have a problem with saving CoreData. Main 3 things to remember:</p> <ol> <li>I'm using NSFetchResultsController to populate my UITableView with data from CoreData</li> <li>I'm lazy downloading images to show them in cells.</li> <li>When downloading of icon ends I converta image data to base64 string and save that string in CoreData.</li> </ol> <p>Problem is that when I try to save CoreData changes after receving icons I get crash. When I commented part of code responsible for making changes to NSManagedObject everything worked fine, but I want to know how can I save that objects without crash.</p> <p>This is where I update NSManagedObject after downloading icon:</p> <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection { if (self.activeDownload &amp;&amp; [self.activeDownload length]&gt;0) { NSString* base64 = [self.activeDownload base64Encoding]; // converting data to base64 NSError* error= nil; Offer* offerDB2 = [self.offer offerObject]; // Offer is NSManagedObject subclass of my Entity if (offerDB2) { [offerDB2 setImageData:base64]; // Setting property value (if commented -&gt; no crash) [CoreDataHandler save]; // This is where App crashes } } self.activeDownload = nil; self.imageConnection = nil; [IconDownloader doNext]; } </code></pre> <p>Now Offer class</p> <pre><code>#import &lt;CoreData/CoreData.h&gt; @interface Offer : NSManagedObject { } @property (nonatomic, retain) NSString * bigInfo; @property (nonatomic, retain) NSNumber * categoryID; @property (nonatomic, retain) NSNumber * databaseID; @property (nonatomic, retain) NSNumber * deleted; @property (nonatomic, retain) NSString * descriptionString; @property (nonatomic, retain) NSNumber * endDate; @property (nonatomic, retain) NSString * extendedInfo; @property (nonatomic, retain) NSNumber * offerType; @property (nonatomic, retain) NSString * photoLink; @property (nonatomic, retain) NSString * physicalUnit; @property (nonatomic, retain) NSString * shopName; @property (nonatomic, retain) NSNumber * size; @property (nonatomic, retain) NSString * sizeUnit; @property (nonatomic, retain) NSString * smallInfo; @property (nonatomic, retain) NSNumber * startDate; @property (nonatomic, retain) NSNumber * unitPrice; @property (nonatomic, retain) NSString * unitPriceName; @property (nonatomic, retain) NSString * imageData; @end #import "Offer.h" @implementation Offer @dynamic bigInfo; @dynamic categoryID; @dynamic databaseID; @dynamic deleted; @dynamic descriptionString; @dynamic endDate; @dynamic extendedInfo; @dynamic offerType; @dynamic photoLink; @dynamic physicalUnit; @dynamic shopName; @dynamic size; @dynamic sizeUnit; @dynamic smallInfo; @dynamic startDate; @dynamic unitPrice; @dynamic unitPriceName, imageData; -(NSNumber*)sectionNumber{ return self.offerType; } @end </code></pre> <p>CrashLog looks like that:</p> <pre><code>*** -[NSCFType evaluateWithObject:]: unrecognized selector sent to instance 0x4354210 Program received signal: “EXC_BAD_ACCESS”. #0 0x32668ec0 in objc_msgSend #1 0x32de2b5e in __CFExceptionProem #2 0x32de2bcc in -[NSObject doesNotRecognizeSelector:] #3 0x32d67b18 in ___forwarding___ #4 0x32d5e840 in __forwarding_prep_0___ #5 0x30537cbe in -[NSFetchedResultsController(PrivateMethods) _objectInResults:] #6 0x30538d16 in -[NSFetchedResultsController(PrivateMethods) _preprocessUpdatedObjects:insertsInfo:deletesInfo:updatesInfo:sectionsWithDeletes:newSectionNames:treatAsRefreshes:] #7 0x3053aa2c in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] #8 0x33f765d8 in _nsnote_callback #9 0x32d9e510 in _CFXNotificationPostNotification #10 0x33f741b2 in -[NSNotificationCenter postNotificationName:object:userInfo:] #11 0x304b4388 in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] #12 0x3050768a in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] #13 0x3049c2b0 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] #14 0x304cb186 in -[NSManagedObjectContext save:] </code></pre> <p>Possible problems:</p> <ol> <li>CoreData while saving can deal with lots of data. Those images converted to base64 can contain lots of characters.</li> <li>Lines #5,#6,#7 say something about NSFetchResultsController.</li> </ol> <p><strong>SOLVED:</strong></p> <p>I simply released NSPredicate wchich was autoreleased object, so after saveing CoreDatra my NSFetchResultsController wanted to update its data, everuthing crashed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload