skip to Main Content

Situation

Hi there,
I am developing an iOS app and while building my project I run into the following error message:
Error: Trace/BPT trap: 5

I didn’t find anything online to fix this problem, so I wanted to know, if anyone here might be able to help.
I also had issues with Cocoapods and my Silicon Mac, so I want to list my steps I’ve tried fixing:

Setup

  • M1 MacBook Pro, macOS 11.1
  • XCode Version 12.4
  • Cocoapods with Pods for Firebase Swift, Auth, Firestore and Storage

Steps I tried fixing

  • cmd + shift + k for cleaning the build folder
  • closing XCode and opening Terminal using Rosetta
  • delete ~/Library/Developer/Xcode/Derived Data – Folder
  • pod deintegrate in project directory
  • delete Podfile.lock, app.xcworkspace, Pods directory
  • pod install
  • in app and pods projects build settings setting Excluded Architectures for any iOS Simulator SDK to arm64
  • setting Build Active Architecture Only to yes
  • convert Pods Project to Swift 5
  • build Pods Project
  • build app project

And then the following error occurs:

Log

Log enty from Merge swiftmodule (x86_64):
https://pastebin.com/MiSKGxB7
(Log way to long, exceeds character limit).

Code

As the error somewhere tells, it occured while trying to serialize the class BaseViewModel, here’s the code from the Base.swift file I wrote containing that class:

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)
                }
            }
        }
    }
    
}

4

Answers


  1. Chosen as BEST ANSWER

    Sorry for the late update on that. But in my case it was either CocoaPods in general or the Firebase Pods, which were not compatible with Apple Silicon at that time.
    I was just using Swift Package Manager and with that, it worked.
    I do not know though, if the problem still exists, because I didn't build another app on the M1 MacBook.


  2. I had the same problem, I am solved it after I updated Quick/Nimble.
    I guess some pod project with x86 files meed to update to support M1

    Login or Signup to reply.
  3. Well for the record, anybody who is experiencing these odd bugs on M1 must read exactly inside the excode compilation error.

    If they are saying a specific class it means xcode can’t compile your code and you should just remove the code and try to compile line by line.
    I know that’s very strange, looks like programming PHP and refreshing a webpage but I’m sure this type of bug can be related to the platform migration.

    In my situation, I had a class that was OK, I started refactoring and instead of xcode showing me the compilation errors, it gave this cryptic BPT5, at reading exactly the description inside of the IDE I could find that my class was the root cause.

    Just remove the code all over you changed and try to compile it again…

    Login or Signup to reply.
  4. I run into this issue after I accidently extract a view as variable without awareness. You shall check your recently committed code to figure it out.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search