Hi,
I tried to extend FileHandle for the sake of some unittests, but I ran into a weird run-time failure that I cannot really figure out.
class FakeFileHandle : FileHandle {
public var written_data : [Data] = []
override func write(_ data: Data) {
written_data.append(data) // fails with EXC_BAD_ACCESS (code=1, address=0x8)
}
}
This code compiles just fine. And when I run the tests where I create a FakeFileHandle creating works fine, like this:
let f = FakeFileHandle()
That call I assume will initialize with an empty array, but when I call f.write execution fails on written_data.append(data) with a EXC_BAD_ACCESS (code=1, address=0x8)-error.
f.write(some_data)
In the debugger I see that any member that I add to the sub-class does not get initialized properly and that seem to be the direct cause of the failure.
Am I wrong to think that the written_data property of the subclass should always be initialized with an empty Array?
What am I missing/doing wrong here?
Thanks in advance!