如何解决输入崩溃的元数据完成功能|访问包含某些不可用组件的类时崩溃
尝试在iOS 12上使用仅包含iOS 14元素的类时发生崩溃。
该类看起来像这样(删除了一些不相关的内容)
public class AssetFuture {
public enum AssetRepresentation {
case asset(asset: PHAsset)
@available(iOS 14,*)
case result(result: PHPickerResult)
}
@available(*,deprecated,message: "Use assetRepresentation instead")
public var asset: PHAsset! {
switch assetRepresentation {
case .asset(asset: let asset):
return asset
default:
return nil
}
}
public let assetRepresentation: AssetRepresentation
init(asset: PHAsset) {
self.assetRepresentation = .asset(asset: asset)
}
@available(iOS 14,*)
init(pickerResult: PHPickerResult) {
self.assetRepresentation = .result(result: pickerResult)
}
我包装仅iOS14元素的方式不正确吗?
它因以下堆栈跟踪而崩溃:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x0000000100520748 in __abort_with_payload ()
#1 0x000000010051fcf8 in abort_with_payload_wrapper_internal ()
#2 0x000000010051fd2c in abort_with_payload ()
#3 0x00000001004dcb40 in dyld::halt(char const*) ()
#4 0x00000001004dcc6c in dyld::fastBindLazySymbol(ImageLoader**,unsigned long) ()
#5 0x00000001f126f708 in _dyld_fast_stub_entry(void*,long) ()
#6 0x00000001f126e210 in dyld_stub_binder ()
#7 0x0000000100637654 in type metadata completion function for AssetFuture.AssetRepresentation ()
可以在这里看到整个项目:https://github.com/eure/AssetsPicker/tree/iOS14
解决方法
枚举不支持不可用的类型
使用其他用户。
例如:
DB::connection(...)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。