起因
最近产品要做一个Widget
小组件,产品的要求必须安排。于是我新创建了一个OC项目,然后创建了一个Widget Extension
。直接运行编译,发编译器报以下错误:
ld: Assertion failed: (reconstituted == (accumulator - _options.machHeaderVmAddr())), function setFixup64, file OutputFile.cpp, line 2864.
ld: Assertion failed: (reconstituted == (accumulator - _options.machHeaderVmAddr())), function setFixup64, file OutputFile.cpp, line 2864.
解决过程
查找资料在官方论坛发现了同样错误,但是没有给出解决方案。
后面通过修改了项目的Projet
支持的最低版本由iOS 15
改为iOS14
可以编译通过。
解决了这个错误之后,发现编译还是有其他错误。
编译报错提示:
1、Type 'Provider' does not conform to protocol 'IntentTimelineProvider'
2、Cannot find 'ConfigurationIntent' in scope
Type 'Provider' does not conform to protocol 'IntentTimelineProvider'
Cannot find 'ConfigurationIntent' in scope
查找资料才知道原因是:
我们在工程中设置了
Class Prefix
,我的项目设置的是CN
。导致Xcode自动生成的是CNConfigurationIntent.swift
,该文件路径是:
/Users/用户名/Library/Developer/Xcode/DerivedData/项目名称/Build/Intermediates.noindex/项目名称.build/Debug-iphonesimulator/widget的名称Extension.build/DerivedSources/IntentDefinitionGenerated/widget的名称/CNConfigurationIntent.swift
但是自动生成的代码又是
ConfigurationIntent
,只需要把代码中的ConfigurationIntent
都改为工程前缀+ConfigurationIntent
(CNConfigurationIntent
)就可以正常运行了。因为项目主工程是OC
,我们在Widget
中创建了两个OC
文件与桥接文件CNHotWidget-Bridging-Header
后,编译发现又开始报错。
Type 'Provider' does not conform to protocol 'IntentTimelineProvider'
Cannot find 'CNConfigurationIntent' in scope
解决这个问题,需要我们在桥接文件CNHotWidget-Bridging-Header
中引入#import "CNConfigurationIntent.h"
。