Ios 未为UIColor定义哈希UIColor需要首先转换颜色空间
我有一个部分用Swift 3.2编写的应用程序,objective-c是用xcode 10构建的,我在一些Swift ViewController中遇到了一个奇怪的崩溃,在我收集的日志上,崩溃发生的原因是我在UILabel上设置了文本(valueLabel.text=“-”)(UILabel是一个普通的标签,没有继承,也没有任何自定义)Ios 未为UIColor定义哈希UIColor需要首先转换颜色空间,ios,swift,uikit,Ios,Swift,Uikit,我有一个部分用Swift 3.2编写的应用程序,objective-c是用xcode 10构建的,我在一些Swift ViewController中遇到了一个奇怪的崩溃,在我收集的日志上,崩溃发生的原因是我在UILabel上设置了文本(valueLabel.text=“-”)(UILabel是一个普通的标签,没有继承,也没有任何自定义) 致命异常:NSInvalidArgumentException 0 CoreFoundation 0x212368ec4异常预处理 1 libobjc.A.dy
致命异常:NSInvalidArgumentException
0 CoreFoundation 0x212368ec4异常预处理
1 libobjc.A.dylib 0x211539a40 objc_异常_抛出
2 CoreFoundation 0x21226f594-[NSCache init]
3 UIKitCore 0x23f14fba0(缺失)
4 UIKitCore 0x23f14fc3c(缺失)
5 UIFoundation 0x21c9ca778 attributeDictionaryHash
6基金会0x212DC8074 HASH探头
7基金会0x212Ce5C24- [ NSRealthHythTabeGeTime:]
8 UIFoundation 0x21c975548+[NSAttributedDialogy newWithDictionary:]
9 UIFoundation 0x21c9778e4-[[NSCachedAttributedString initWithString:attributes:]
10 UI21C9E5B98型钢绞线绞车
11 UIFoundation 0x21c9697e4-[NSString(NSExtendedStringDrawing)boundingRectWithSize:选项:属性:上下文:]
12 UIKitCore 0x23f90c9a0(缺失)
18 ole委托人0x100e336ac$S14test\u应用程序18 CardViewController 11重置布局33\u 2D3 FEF56CDB4998F7394998E4FE67LLYYF(CardViewController.swift:103)
19 ole委托0x100e327b4$S14test\u app18CardViewControllerc17ViewwillUnsearyySBF(CardViewController.swift:73)
20 ole委托0x100e32804$S14test\u App18CardViewControllerc17ViewwillUnsearyySBFTO()
21 UIKitCore 0x23ef39068(缺失)
43 CoreFoundation 0x2122f87cc\uuuu CFRUNLOOP\u正在调用\uu OUT\u来调用\uu OBSERVER\u CALLBACK\u函数__
44 CoreFoundation 0x2122f3460\uuu cfrunloopdoobserver
45 CoreFoundation 0x2122f3a00\uuuu CFRunLoopRun
46 CoreFoundation 0x2122f31f0 CFRunLoopRunSpecific
47图形服务0x21456c584 GSEventRunModal
48 UIKitCore 0x23f4fad40(缺失)
49.0x100b37f74干管(干管m:14)
50 libdyld.dylib 0x211db2bb4开始
因此,我的问题是,有谁曾经遇到过这种崩溃,并提出了解决方案建议?每当您通过
UIColor.init
实例化UIColor时,都会生成UIPlaceholder Color的实例,该实例不带任何参数。这方面的问题是,它在UIKit的语义中完全有效,并导致它被显示显示为UIColor.clear
,可能是
中断点是试图将其与CoreGraphics语义结合使用。UIPlaceholder颜色的底层存储不具有颜色空间和任何颜色值存储,因此,无法使用CGColor
getter将其转换为CGColor。hash
getter也是如此
您如何解决这种情况?确定您在哪里调用
UIColor.init
,并将其替换为UIColor.clear
,它将很容易转换为CGColor。这非常有用。谢谢。我有一些UIColor()的实例在ios13*中没有引起任何问题,但在ios12上会莫名其妙地崩溃的初始化。您为我节省了时间和精力
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