title: Xcode Trace/BPT trap: 5
body: <h1>Situation</h1>
  <p>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</p>
  <p>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:</p>
  <h1>Setup</h1>
  <ul>
  <li>M1 MacBook Pro, macOS 11.1</li>
  <li>XCode Version 12.4</li>
  <li>Cocoapods with Pods for Firebase Swift, Auth, Firestore and Storage</li>
  </ul>
  <h1>Steps I tried fixing</h1>
  <ul>
  <li>cmd + shift + k for cleaning the build folder</li>
  <li>closing XCode and opening Terminal using Rosetta</li>
  <li>delete ~/Library/Developer/Xcode/Derived Data - Folder</li>
  <li>pod deintegrate in project directory</li>
  <li>delete Podfile.lock, app.xcworkspace, Pods directory</li>
  <li>pod install</li>
  <li>in app and pods projects build settings setting Excluded Architectures for any iOS Simulator SDK to arm64</li>
  <li>setting Build Active Architecture Only to yes</li>
  <li>convert Pods Project to Swift 5</li>
  <li>build Pods Project</li>
  <li>build app project</li>
  </ul>
  <p>And then the following error occurs:</p>
  <h1>Log</h1>
  <p>Log enty from Merge swiftmodule (x86_64):
  <a href="https://pastebin.com/MiSKGxB7" rel="nofollow noreferrer">https://pastebin.com/MiSKGxB7</a>
  (Log way to long, exceeds character limit).</p>
  <h1>Code</h1>
  <p>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:</p>
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  import Firebase
  import FirebaseFirestore
  import Combine
  
  protocol BaseModel: Identifiable, Codable {
      var id: String? { get set }
      var collection: String { get }
      init()
  }
  
  class BaseViewModel&lt;T: BaseModel&gt;: 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&lt;T&gt;, rhs: BaseViewModel&lt;T&gt;) -&gt; Bool {
          lhs.model.id == rhs.model.id
      }
      
      func load(completion: @escaping (Bool) -&gt; 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(&quot;Error fetching document: \(error!)&quot;)
                      return
                  }
                  
                  do {
                      guard let data = try doc.data(as: T.self) else {
                          print(&quot;Document empty \(type(of: self.model)) with id \(id)&quot;)
                          return
                      }
                      self.model = data
                      self.loadSubData {finished in
                          if finished{
                              completion(true)
                          }
                      }
                  } catch {
                      print(error.localizedDescription)
                  }
              }
          }
      }
      
      func loadSubData(completion: @escaping(Bool) -&gt; Void = {finished in}) {
          fatalError(&quot;Must be overridden!&quot;)
      }
      
      func loadDataByIDs&lt;T, S&gt;(from list: [String], appender: @escaping (T) -&gt; Void) where T: BaseViewModel&lt;S&gt;, 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)
                  }
              }
          }
      }
      
  }
  </code></pre>