Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXC_BAD_ACCESS when trying to encode a subclass of a Codable-conformant class

I must be a moron or something but I'm scratching my head for a third day in a row and can't figure out what's going wrong with my intention to encode some JSON data in my Swift program...

Here's the situation: I've got two classes as follows:

class Node: Codable {
    // Nothing in here
}

and

class Shape: Node {
    // No code here too
}

Then, I have an attempt to encode the subclass as follows:

do {
    let encodedData = try JSONEncoder().encode(Shape())
} catch {
    print(error)
}

This is all I have added to an empty Single View App project. When I run it, I get "Thread 1: EXC_BAD_ACCESS (code=1, address=0x350)" crash.

Actual screenshot

Of course, initially my classes used to have a lot of properties which were Codable too. I thought it was any of them, so I stripped them off but it appears it's not the properties that are causing the crash...

I'm running Xcode 9.3 on a High Sierra MacBook Pro. Is there anyone willing to reproduce this or anyone already bumped his head into such an odd behavior?

like image 760
Stoyan Avatar asked Sep 20 '25 11:09

Stoyan


1 Answers

This is a known bug and you can work around it by turning on Whole Module Compilation mode for the Debug configuration, or by upgrading to Xcode 10 beta.

like image 60
matt Avatar answered Sep 23 '25 00:09

matt