Saturday, 12 October 2019

EXC_BAD_ACCESS in parent class init() with Xcode 10.2

I’ve been pulling my hair on a weird bug in Xcode 10.2. I’ve had this swift util method to decode JSON objects using ObjectMapper as I can’t call ObjectMapper from ObjectiveC:

@objc static func mapModel(fromClass: AnyClass, jsonDict: [String : Any]) -> Any {
    guard let mappableClass = fromClass as? Mappable.Type else {
        fatalError("class \(fromClass) is not Mappable")
    }
    return mappableClass.init(JSON: jsonDict)!
}

I had to use AnyClass because Mappable is not compatible with ObjC. This code has been working fine until I updated to Xcode 10.2.

It’s still working fine with devices on iOS 12.2 and above but it’s crashing with a EXC_BAD_ACCESS at the init() line on iOS 12.1 and below. Does anyone have any idea why it’s crashing on older iOS versions and how I can change that code?



from EXC_BAD_ACCESS in parent class init() with Xcode 10.2

No comments:

Post a Comment