zhangferry/iOSWeeklyLearning

Cateogry和Extension使用相同名称扩展的问题

Closed this issue · 1 comments

bug出现的现象是什么样的?

对SDK的一个类扩展时,使用了相同的名称扩展

  1. Extension扩展
    image

  2. Cateogry扩展,并实现了type的getter方法
    image

  3. 错误不是每次都会出现,XCode12.3一开始是偶现,出现后就一直是报错。

Unable to execute command: Segmentation fault: 11
Clang frontend command failed due to signal (use -v to see invocation)
Diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
Diagnostic msg:


PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
Diagnostic msg: /var/folders/tp/4kw93qbn7tb20cbpn14fmwk00000gn/T/RLWifiConfigFailedViewController-243a91.m
Diagnostic msg: /var/folders/tp/4kw93qbn7tb20cbpn14fmwk00000gn/T/RLWifiConfigFailedViewController-243a91.cache
Diagnostic msg: /var/folders/tp/4kw93qbn7tb20cbpn14fmwk00000gn/T/RLWifiConfigFailedViewController-243a91.sh
Diagnostic msg: /var/folders/tp/4kw93qbn7tb20cbpn14fmwk00000gn/T/RLWifiConfigFailedViewController-243a91.crash
Diagnostic msg:


是如何解决的?

将Cateogry扩展和Extension扩展的扩展名设置为不同的,这个错误解决了。

bug引发的反思?(如果有的话)bug隐含了什么知识点

extension在编译期决议,它就是类的一部分,在编译期和头文件里的@interface以及实现文件里的。
然后category是在运行期加入hashTable表,extension扩展的名称和category一样,这个时候可能在hashTable表上已经有了对应名称的数据,category在加入时就会出错。XCode这时候也可能错以为维护hashTable表出错,让提交对应的bug到http://developer.apple.com/bugreporter/。

已采纳