The following simple function will cause Xcode 12E262 to have "Abort: trap 6" during compilation.
import UIKit
import CoreData
class ViewController: UIViewController {
func xyz() {
let container = NSPersistentContainer(name: "xyz")
let batchUpdateRequest = NSBatchUpdateRequest(entityName: "xyz")
let batchUpdateResult = try! container.viewContext.execute(batchUpdateRequest) as? NSBatchUpdateResult
guard let batchUpdateResult = batchUpdateResult else { return }
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
We will not observe "Abort: trap 6", if under Build Settings, we are using "Optimize for Speed" in Debug, instead of "No Optimization"
We can also avoid "Abort: trap 6", if we change the following code
guard let batchUpdateResult = batchUpdateResult else { return }
to
guard let batchUpdateResult2 = batchUpdateResult else { return }
May I know, why is it so?
A simpler code example to reproduce problem, without CoreData would be
import UIKit
class ViewController: UIViewController {
func getAny() throws -> Any? {
return nil
}
func xyz() {
let name = try! getAny() as? UIViewController
guard let name = name else { return }
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}