-2

I am getting a this crash while adding Model Object in database, i have symbolicated the crash,

here is the stack trace for crash

SIGSEGV SEGV_MAPERR

libobjc.A.dylib 0x366746ba objc_retain + 8 1
Foundation 0x2907887d _encodeObject + 1066 2
Foundation 0x29079a6f -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 400 3
Foundation 0x2907a051 -[NSArray(NSArray) encodeWithCoder:] + 182 4
Foundation 0x2907887d _encodeObject + 1066 5
MyApp 0x000d3da3 -[WorkOrder encodeWithCoder:] (WorkOrder.m:97) 6
Foundation 0x2907887d _encodeObject + 1066 7
Foundation 0x2907ebd9 +[NSKeyedArchiver archivedDataWithRootObject:] + 154 8
CoreData 0x2809c861 -[NSSQLiteConnection execute] + 1762 9
CoreData 0x280d99af -[NSSQLiteConnection updateRow:] + 544 10
CoreFoundation 0x283a8965 ____NSDictionaryEnumerate_block_invoke421 + 22 11
CoreFoundation 0x282b8740 CFBasicHashApply + 118 12
CoreFoundation 0x283a6367 __NSDictionaryEnumerate + 268 13
CoreData 0x2816bdf3 -[NSSQLCore writeChanges] + 544 14
CoreData 0x280d493d -[NSSQLCore saveChanges:] + 854 15
CoreData 0x280a2b25 -[NSSQLCore executeRequest:withContext:error:] + 734 16
CoreData 0x28154a35 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3622 17
CoreData 0x2815ca13 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 260 18
libdispatch.dylib 0x36bc52cf _dispatch_client_callout + 20 19
libdispatch.dylib 0x36bcca3d _dispatch_barrier_sync_f_invoke + 46 20
CoreData 0x2814ef8d _perform + 134 21
CoreData 0x280a2703 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 312 22
CoreData 0x280c47d1 -[NSManagedObjectContext save:] + 854 23
MyApp 0x0011f83f __37-[WorkOrderManagement saveWorkOrder:]_block_invoke (WorkOrderManagement.m:96) 24
libdispatch.dylib 0x36bc52e3 _dispatch_call_block_and_release + 8 25
libdispatch.dylib 0x36bcf381 _dispatch_root_queue_drain + 1386 26
libdispatch.dylib 0x36bd03c3 _dispatch_worker_thread3 + 92 27
libsystem_pthread.dylib 0x36d2cdc1 _pthread_wqthread + 666 28
libsystem_pthread.dylib 0x36d2cb14 start_wqthread + 6

Here is my code. After symbolicating found out that the suspected line of crash is here in this code block is
[coder encodeObject:self.lstSelectedEmployees forKey:@"lstSelectedEmployees"];

any help will be highly appreciated.

-(void) encodeWithCoder:(NSCoder *)coder {
        [coder encodeObject:self.workOrderID forKey:@"workOrderID"];
        [coder encodeObject:self.projectID forKey:@"projectID"];
        [coder encodeObject:self.locationID forKey:@"locationID"];
        [coder encodeObject:self.service forKey:@"service"];
        [coder encodeObject:self.suggestedQty forKey:@"suggestedQty"];
        [coder encodeObject:self.note forKey:@"note"];
        [coder encodeInt:self.appDuration forKey:@"appDuration"];
        [coder encodeObject:self.forDate forKey:@"forDate"];
        [coder encodeObject:self.quantity forKey:@"quantity"];
        [coder encodeObject:self.lstPictures forKey:@"lstPictures"];
        [coder encodeObject:self.lstAudios forKey:@"lstAudios"];
        [coder encodeObject:self.startTime forKey:@"startTime"];
        [coder encodeObject:self.endTime forKey:@"endTime"];
        [coder encodeObject:self.comments forKey:@"comments"];
        [coder encodeObject:self.assignedToEmployeeName forKey:@"assignedToEmployeeName"];
        [coder encodeBool:self.isDone forKey:@"isDone"];
        [coder encodeBool:self.isPartial forKey:@"isPartial"];
        [coder encodeObject:self.lstSelectedEmployees forKey:@"lstSelectedEmployees"];
        [coder encodeObject:self.lstSelectedEquipment forKey:@"lstSelectedEquipment"];
        [coder encodeObject:self.lstSelectedMaterials forKey:@"lstSelectedMaterials"];
        [coder encodeObject:self.selectedVehicle forKey:@"selectedVehicle"];
        [coder encodeInt:self.qtySelectedIndex forKey:@"qtySelectedIndex"];
        [coder encodeInteger:self.elapsedCount forKey:@"elapsedCount"];
        [coder encodeBool:self.counterRunning forKey:@"counterRunning"];
        [coder encodeObject:self.lstEmployees forKey:@"lstEmployees"];
        [coder encodeObject:self.lstEquipment forKey:@"lstEquipment"];
        [coder encodeObject:self.lstChecklist forKey:@"lstChecklist"];
        [coder encodeBool:self.locationChecklistAdded forKey:@"locationChecklistAdded"];
        [coder encodeObject:self.scaleValue forKey:@"scaleValue"];
        [coder encodeObject:self.lstChecklistitems forKey:@"lstChecklistitems"];
 }

1 Answers1

0

the last object to be encoded before the crash is an NSArray, make sure that the objects in that array are allowed property list types

vadian
  • 274,689
  • 30
  • 353
  • 361
  • self.lstSelectedEmployees is the nsmutablearray of Employee objects, – Bilal Ahmed Mughal Jul 03 '15 at 11:40
  • how to make sure the objects in array are allows property types ? – Bilal Ahmed Mughal Jul 03 '15 at 11:42
  • the basic allowed types are NSString, NSNumber, NSDate, NSData and the collection types NSArray and NSDictionary which also must contain property list compliant types. Custom types must be encoded with encodeWithCoder and archived with NSKeyedArchiver – vadian Jul 03 '15 at 11:49
  • and sir how to encode NSmutableArray to store is NSObject and get back, and what if i am encoding NSmutableArray ? like below ? [coder encodeObject:self.lstSelectedEmployees forKey:@"lstSelectedEmployees"]; – Bilal Ahmed Mughal Jul 03 '15 at 11:54
  • for a mutable array call `mutableCopy` method after decoding – vadian Jul 03 '15 at 11:56
  • sorry I dont get it where should i user mutablecopy? – Bilal Ahmed Mughal Jul 03 '15 at 11:58
  • there is no difference to encode NSArray or NSMutableArray. When you get it back you get an immutable array. To assign the object to NSMutableArray you have to call `mutableCopy` – vadian Jul 03 '15 at 12:04
  • self.lstSelectedEmployees = [[coder decodeObjectForKey:@"lstSelectedEmployees"] mutableCopy]; is it fine ? will i get exception now>? and ecoding is like [coder encodeObject:self.lstSelectedEmployees forKey:@"lstSelectedEmployees"]; – Bilal Ahmed Mughal Jul 03 '15 at 12:14
  • you have to implement the NSCoding protocol also for your Employee class and archive the object with NSKeyedArchiver. Please read the documentation about NSCoding and NSKeyedArchiver – vadian Jul 03 '15 at 12:21