hash not defined for the UIColor UIPlaceholderColor need to first convert colorspace

Viewed 904

I have an app that is written partially in Swift 3.2 and objective-c built with xcode 10, I am having a strange crash in some Swift ViewControllers, on the log that I collected, the line from that crash what is happening is that I am setting the text (valueLabel.text = "-") on a UILabel (the UILabel is a normal one no inheritance nor any customization).

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x212368ec4 __exceptionPreprocess
1  libobjc.A.dylib                0x211539a40 objc_exception_throw
2  CoreFoundation                 0x21226f594 -[NSCache init]
3  UIKitCore                      0x23f14fba0 (Missing)
4  UIKitCore                      0x23f14fc3c (Missing)
5  UIFoundation                   0x21c9ca778 attributeDictionaryHash
6  Foundation                     0x212dc8074 hashProbe
7  Foundation                     0x212ce5c24 -[NSConcreteHashTable getItem:]
8  UIFoundation                   0x21c975548 +[NSAttributeDictionary newWithDictionary:]
9  UIFoundation                   0x21c9778e4 -[_NSCachedAttributedString initWithString:attributes:]
10 UIFoundation                   0x21c9e5b98 __NSStringDrawingEngine
11 UIFoundation                   0x21c9697e4 -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:]
12 UIKitCore                      0x23f90c9a0 (Missing)
18 ole-consignado                 0x100e336ac $S14test_app18CardViewControllerC11resetLayout33_2E2D3FEF56CDB4998F73949398E4FE67LLyyF (CardViewController.swift:103)
19 ole-consignado                 0x100e327b4 $S14test_app18CardViewControllerC17viewWillDisappearyySbF (CardViewController.swift:73)
20 ole-consignado                 0x100e32804 $S14test_app18CardViewControllerC17viewWillDisappearyySbFTo (<compiler-generated>)
21 UIKitCore                      0x23ef39068 (Missing)
43 CoreFoundation                 0x2122f87cc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
44 CoreFoundation                 0x2122f3460 __CFRunLoopDoObservers
45 CoreFoundation                 0x2122f3a00 __CFRunLoopRun
46 CoreFoundation                 0x2122f31f0 CFRunLoopRunSpecific
47 GraphicsServices               0x21456c584 GSEventRunModal
48 UIKitCore                      0x23f4fad40 (Missing)
49 ole-consignado                 0x100b37f74 main (main.m:14)
50 libdyld.dylib                  0x211db2bb4 start

So my question is any one has encountered that crash before and have a solution suggestion?

1 Answers

An instance of UIPlaceholderColor is produced whenever you instantiate a UIColor via the UIColor.init, that takes no parameters. The thing about this is that it is completely valid in the semantics of UIKit, and leads to it being displayed as a UIColor.clear, probably.

The breaking point is an attempt to use it with CoreGraphics semantics. The underlying storage of the UIPlaceholderColor does not feature a color space and any color value storage, and for this reason, can not be converted to a CGColor using the cgColor getter. hash getter is the same story.

How do you resolve this situation? Identify, where exactly are you calling for UIColor.init and replace it with UIColor.clear, which will be easily convertible to CGColor.

Related