This code is in the initialization for a subclass of a UIView object. The UIView is circular in shape and displays a percentChange value using a nested UILabel. The following code resizes the UILabel and the font size to fit the text in the UIView. percentChange is some Int.

    let stringAttrs: NSMutableDictionary = [NSFontAttributeName: stringFont, NSForegroundColorAttributeName: self.GreenColor]

    if percentChange > 0 {
        self.layer.borderColor = self.GreenColor.CGColor
        stringAttrs.setValue(self.GreenColor, forKey: NSForegroundColorAttributeName)
        indicator = ""

    }
    else if percentChange < 0 {
        self.layer.borderColor = UIColor.redColor().CGColor
        stringAttrs.setValue(UIColor.redColor().CGColor, forKey: NSForegroundColorAttributeName)
        indicator = "▼"
    }
    else {
        self.layer.borderColor = UIColor.grayColor().CGColor
        stringAttrs.setValue(UIColor.grayColor().CGColor, forKey: NSForegroundColorAttributeName)
        indicator = ""
    }


    do {
        fontPointSize -= 0.5
        stringFont = UIFont(name: "AmericanTypewriter", size: fontPointSize)!
        stringAttrs.setValue(stringFont, forKey: NSFontAttributeName)
        percentChangeLabel.attributedText = NSAttributedString(string: "\(indicator)\(abs(Int(percentChange)))%", attributes: stringAttrs)
        percentChangeLabel.sizeToFit()
    } while percentChangeLabel.frame.width > (self.frame.width - PaddingLeft - PaddingRight) 

The three conditionals set indicator with "▲" (percentChange > 0), "▼" (percentChange < 0), or "" (percentChange == 0). Heres the bizarre thing, the app will only crash if percentChange is 0 and if indicator != "▲" or != "▼". If I change indicator to be "▼" or "▲" in the else statement, the app works fine. Every other character/string I have tried so far results in the same crash. Setting indicator to "" for percentChange > 0 or percentChange < 0 also does not cause any problems. I have attached the crash log and was hoping if someone could help me figure out whats going on, or perhaps guide me in the right direction.

2014-11-04 22:09:48.208 Cassandra[796:11817] -[__NSCFType set]: unrecognized selector sent to instance 0x7ff951b475f0

2014-11-04 22:09:48.210 Cassandra[796:11817] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType set]: unrecognized selector sent to instance 0x7ff951b475f0'

*** First throw call stack:

(

0   CoreFoundation                      0x000000010937af35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010b36fbb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010938204d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x00000001092da27c ___forwarding___ + 988
4   CoreFoundation                      0x00000001092d9e18 _CF_forwarding_prep_0 + 120
5   UIFoundation                        0x000000010f42dcf3 __NSStringDrawingEngine + 28766
6   UIFoundation                        0x000000010f42e1ec -[NSAttributedString(NSExtendedStringDrawing) drawWithRect:options:context:] + 561
7   UIKit                               0x000000010a282a4c -[UILabel _drawTextInRect:baselineCalculationOnly:] + 5549
8   UIKit                               0x000000010a280cab -[UILabel drawTextInRect:] + 624
9   UIKit                               0x000000010a282c60 -[UILabel drawRect:] + 100
10  UIKit                               0x000000010a130569 -[UIView(CALayerDelegate) drawLayer:inContext:] + 496
11  QuartzCore                          0x0000000109f42942 -[CALayer drawInContext:] + 113
12  QuartzCore                          0x0000000109e3fd5b CABackingStoreUpdate_ + 2793
13  QuartzCore                          0x0000000109f42851 ___ZN2CA5Layer8display_Ev_block_invoke + 59
14  QuartzCore                          0x0000000109f426e9 _ZN2CA5Layer8display_Ev + 1469
15  QuartzCore                          0x0000000109f37801 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 301
16  QuartzCore                          0x0000000109f37889 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
17  QuartzCore                          0x0000000109ea563e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
18  QuartzCore                          0x0000000109ea674a _ZN2CA11Transaction6commitEv + 390
19  QuartzCore                          0x0000000109ea6db5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
20  CoreFoundation                      0x00000001092afdc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
21  CoreFoundation                      0x00000001092afd20 __CFRunLoopDoObservers + 368
22  CoreFoundation                      0x00000001092a5b53 __CFRunLoopRun + 1123
23  CoreFoundation                      0x00000001092a5486 CFRunLoopRunSpecific + 470
24  GraphicsServices                    0x000000010e05e9f0 GSEventRunModal + 161
25  UIKit                               0x000000010a0b7420 UIApplicationMain + 1282
26  Cassandra                           0x0000000108da8ade top_level_code + 78
27  Cassandra                           0x0000000108da8b1a main + 42
28  libdyld.dylib                       0x000000010bb49145 start + 1
)

libc++abi.dylib: terminating with uncaught exception of type NSException

Update: The UIView above is nested in a subclass of UITableCellView which is being added to a UITableView. It seems that the crash occurs consistently after the last UITableViewCell is added.

Related posts

Recent Viewed