Question

I'm getting an unrecognized selector error with NSCFNumber and UILabel drawTextInRect: in the stack trace. This is what the stack trace looks like:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xad5a260'
*** First throw call stack:
(
    0   CoreFoundation                      0x01f039e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c838e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01fa0a43 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x01ef3d0b ___forwarding___ + 1019
    4   CoreFoundation                      0x01ef38ee _CF_forwarding_prep_0 + 14
    5   UIKit                               0x00b02773 -[UILabel _shadow] + 45
    6   UIKit                               0x00b03bd2 -[UILabel drawTextInRect:] + 70
    7   UIKit                               0x00b0610c -[UILabel drawRect:] + 98
    8   UIKit                               0x009b4893 -[UIView(CALayerDelegate) drawLayer:inContext:] + 504
    9   QuartzCore                          0x0060db39 -[CALayer drawInContext:] + 123
    10  QuartzCore                          0x0060da6a _ZL16backing_callbackP9CGContextPv + 96
    11  QuartzCore                          0x004fbf3c CABackingStoreUpdate_ + 2656
    12  QuartzCore                          0x0060da02 ___ZN2CA5Layer8display_Ev_block_invoke + 93
    13  QuartzCore                          0x00641ee3 x_blame_allocations + 15
    14  QuartzCore                          0x0060d86d _ZN2CA5Layer8display_Ev + 1519
    15  QuartzCore                          0x0060dab9 -[CALayer _display] + 33
    16  QuartzCore                          0x0060d276 _ZN2CA5Layer7displayEv + 144
    17  QuartzCore                          0x0060da93 -[CALayer display] + 33
    18  QuartzCore                          0x00601c43 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 323
    19  QuartzCore                          0x00601cbc _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
    20  QuartzCore                          0x005683ee _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    21  QuartzCore                          0x00569779 _ZN2CA11Transaction6commitEv + 393
    22  QuartzCore                          0x00569e4c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    23  CoreFoundation                      0x01ecbb6e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    24  CoreFoundation                      0x01ecbabf __CFRunLoopDoObservers + 399
    25  CoreFoundation                      0x01ea9a54 __CFRunLoopRun + 1076
    26  CoreFoundation                      0x01ea91d3 CFRunLoopRunSpecific + 467
    27  CoreFoundation                      0x01ea8feb CFRunLoopRunInMode + 123
    28  GraphicsServices                    0x03d1c5ee GSEventRunModal + 192
    29  GraphicsServices                    0x03d1c42b GSEventRun + 104
    30  UIKit                               0x009463db UIApplicationMain + 1225
    31  PocketCTF                           0x00026e8d main + 141
    32  libdyld.dylib                       0x02881725 start + 0
)

I'm not sure what line is causing this error because Xcode just breakpoints to the main run loop. I've tried using exception and symbolic breakpoints to see what line is causing the issue but no avail. Is there anything I can do to find what line is causing this?

Was it helpful?

Solution

After hours of debugging, of course I find the solution after I post on here.. I was trying to set text based on a NSDictionary value like so,

[label setText:[json objectForKey:@"text"]];

But instead of id, UILabel wanted NSString (as pointed out by @danielbeard)

[label setText:[[json objectForKey:@"text"] stringValue]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top