Group Group Group Group Group Group Group Group Group

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UnCloudNotes.Attachment copyWithZone:]: unrecognized selector sent to instance 0x60000280fac0'

Hi. I am trying to build the UnCloudNotes app after making the changes in v2 to v3 in chapter 6. I am getting the following traceback:

2019-11-19 19:10:07.317193-0800 UnCloudNotes[6010:557927] -[UnCloudNotes.Attachment copyWithZone:]: unrecognized selector sent to instance 0x60000280fac0
2019-11-19 19:10:07.320475-0800 UnCloudNotes[6010:557927] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UnCloudNotes.Attachment copyWithZone:]: unrecognized selector sent to instance 0x60000280fac0'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff50b97b20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23c6ff94 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
	3   CoreFoundation                      0x00007fff23c53dac ___forwarding___ + 1436
	4   CoreFoundation                      0x00007fff23c55f38 _CF_forwarding_prep_0 + 120
	5   libswiftFoundation.dylib            0x00007fff51539981 $sSh10FoundationE26_forceBridgeFromObjectiveC_6resultySo5NSSetC_ShyxGSgztFZ + 97
	6   libswiftFoundation.dylib            0x00007fff51534f78 $sSh10FoundationE36_unconditionallyBridgeFromObjectiveCyShyxGSo5NSSetCSgFZ + 56
	7   UnCloudNotes                        0x0000000105ebc46d $s12UnCloudNotes4NoteC16latestAttachmentAA0F0CSgvg + 157
	8   UnCloudNotes                        0x0000000105ebc364 $s12UnCloudNotes4NoteC5imageSo7UIImageCSgvg + 68
	9   UnCloudNotes                        0x0000000105eb531f $s12UnCloudNotes0C18ListViewControllerC05tableE0_12cellForRowAtSo07UITableE4CellCSo0lE0C_10Foundation9IndexPathVtF + 367
	10  UnCloudNotes                        0x0000000105eb5765 $s12UnCloudNotes0C18ListViewControllerC05tableE0_12cellForRowAtSo07UITableE4CellCSo0lE0C_10Foundation9IndexPathVtFTo + 165
	11  UIKitCore                           0x00007fff47a5468e -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 781
	12  UIKitCore                           0x00007fff47a1d667 -[UITableView _updateVisibleCellsNow:] + 3081
	13  UIKitCore                           0x00007fff47a3d78b -[UITableView layoutSubviews] + 194
	14  UIKitCore                           0x00007fff47d34d01 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
	15  QuartzCore                          0x00007fff2b138d41 -[CALayer layoutSublayers] + 255
	16  QuartzCore                          0x00007fff2b13ef33 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
	17  QuartzCore                          0x00007fff2b14a86a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
	18  QuartzCore                          0x00007fff2b0917c8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
	19  QuartzCore                          0x00007fff2b0c6ad1 _ZN2CA11Transaction6commitEv + 643
	20  UIKitCore                           0x00007fff47867461 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
	21  CoreFoundation                      0x00007fff23bb204c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	22  CoreFoundation                      0x00007fff23bb17b8 __CFRunLoopDoBlocks + 312
	23  CoreFoundation                      0x00007fff23bac644 __CFRunLoopRun + 1284
	24  CoreFoundation                      0x00007fff23babe16 CFRunLoopRunSpecific + 438
	25  GraphicsServices                    0x00007fff38438bb0 GSEventRunModal + 65
	26  UIKitCore                           0x00007fff4784fb48 UIApplicationMain + 1621
	27  UnCloudNotes                        0x0000000105ec30bb main + 75
	28  libdyld.dylib                       0x00007fff51a1dc25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

I really don’t understand what the error code is trying to get at. My exact code is here if anyone wants to try it: https://github.com/AlexMarshall12/migration-issues-ios . It seems to me to match the v3 project code in the directory pretty much exactly. But maybe I have something configured slightly incorrectly?

Hi alexyz

In the section called A manual migration (p169/170) it says to create a non-optional attribute named image Your attribute was optional.

Then… Finally, create a to-many relationship from the Note entity to the Attachment entity. Your relationship was one-to-one.

When I made these changes the code compiled and I was able to add an image to the Notes. I think you may have more errors but this should help you find them. Hope this helps.

@magnas Thank you for sharing your solution - much appreciated!