【发布时间】:2021-01-30 13:53:05
【问题描述】:
情况
你好, 我正在开发一个 iOS 应用程序,在构建我的项目时遇到以下错误消息: 错误:跟踪/BPT 陷阱:5
我没有在网上找到任何东西来解决这个问题,所以我想知道这里是否有人可以提供帮助。 我也遇到了 Cocoapods 和 Silicon Mac 的问题,所以我想列出我尝试修复的步骤:
设置
- M1 MacBook Pro,macOS 11.1
- XCode 版本 12.4
- 带有用于 Firebase Swift、Auth、Firestore 和 Storage 的 Pod 的 Cocoapods
我尝试修复的步骤
- cmd + shift + k 清理构建文件夹
- 使用 Rosetta 关闭 XCode 并打开终端
- 删除 ~/Library/Developer/Xcode/Derived Data - 文件夹
- 项目目录中的 pod deintegrate
- 删除 Podfile.lock、app.xcworkspace、Pods 目录
- pod 安装
- 在应用程序和 Pod 项目构建设置中,将任何 iOS 模拟器 SDK 的排除架构设置为 arm64
- 将“仅构建活动架构”设置为“是”
- 将 Pods 项目转换为 Swift 5
- 构建 Pod 项目
- 构建应用项目
然后出现如下错误:
日志
来自 Merge swiftmodule (x86_64) 的日志实体: https://pastebin.com/MiSKGxB7 (日志太长,超过字符限制)。
代码
正如某处的错误所说,它是在尝试序列化 BaseViewModel 类时发生的,这是我编写的包含该类的 Base.swift 文件中的代码:
import SwiftUI
import Firebase
import FirebaseFirestore
import Combine
protocol BaseModel: Identifiable, Codable {
var id: String? { get set }
var collection: String { get }
init()
}
class BaseViewModel<T: BaseModel>: ObservableObject, Identifiable, Equatable {
@Published var model: T
var id: String {
didSet {
self.model.id = id
}
}
var cancellables = [AnyCancellable]()
private var db = Firestore.firestore()
required init(){
let model = T.init()
self.model = model
self.id = model.id ?? UUID().uuidString
}
required init(id: String) {
var model = T.init()
model.id = id
self.model = model
self.id = id
}
init(model: T) {
self.model = model
self.id = model.id ?? UUID().uuidString
}
static func ==(lhs: BaseViewModel<T>, rhs: BaseViewModel<T>) -> Bool {
lhs.model.id == rhs.model.id
}
func load(completion: @escaping (Bool) -> Void = {finished in}){
if let id = model.id {
self.id = id
db.collection(model.collection).document(id).getDocument { docSnapshot, error in
guard let doc = docSnapshot else {
print("Error fetching document: \(error!)")
return
}
do {
guard let data = try doc.data(as: T.self) else {
print("Document empty \(type(of: self.model)) with id \(id)")
return
}
self.model = data
self.loadSubData {finished in
if finished{
completion(true)
}
}
} catch {
print(error.localizedDescription)
}
}
}
}
func loadSubData(completion: @escaping(Bool) -> Void = {finished in}) {
fatalError("Must be overridden!")
}
func loadDataByIDs<T, S>(from list: [String], appender: @escaping (T) -> Void) where T: BaseViewModel<S>, S: BaseModel {
for id in list {
let viewModel = T.init(id: id)
viewModel.load{finished in
if finished {
appender(viewModel)
}
}
}
}
func save(){
do {
let _ = try db.collection(model.collection).addDocument(from: model)
} catch {
print(error)
}
}
func update(){
if let id = model.id {
do {
try db.collection(model.collection).document(id).setData(from: model)
} catch {
print(error.localizedDescription)
}
}
}
func delete(){
if let id = model.id {
db.collection(model.collection).document(id).delete() { error in
if let error = error {
print(error.localizedDescription)
}
}
}
}
}
【问题讨论】:
标签: swift xcode swiftui cocoapods apple-silicon