I have the following function:
func delete()
{
if (deleteCounter == 0)
{
print("Deletion Start")
deleteCounter = 1
// Execute async delete task
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),
{
if (self.textDocumentProxy.isProxy())
{
for _ in 1..<50
{
(self.textDocumentProxy as UIKeyInput).deleteBackward()
}
}
print("Deletion End")
self.deleteCounter = 0
})
} else
{
print("Denying deletion")
}
}
where deleteCounter
is a integer that is set to zero by default.
The code is supposed to function so when the delete key on my custom keyboard app extension is pressed, it will not call the delete loop if it is still looping, thus preventing too many method calls.
The code seems to be working fine, but if I hit the delete button rapidly (thus calling this function repeatedly) for a large period of time I get the following error:
Thread 3: EXC_BAD_ACCESS(code = 1,address=0x10)
on this line:
(self.textDocumentProxy as UIKeyInput).deleteBackward()
I do not ever modify the self.textDocumentProxy
object because it is just a default object that IOS provides for keyboard extensions that you can always access.
After reading up on the EXC_BAD_ACCESS
error I figured out that it was probably because the self.textDocumentProxy
object was being released from memory at some point.
How do I prevent self.textDocumentProxy
from being released, or how do I make sure that I can always get a non-released copy of the object?
UPDATE:
I enabled zombie objects and I get the following error message:
[_UIInputViewControllerOutput setKeyboardOutputs:]: message sent to deallocated instance 0x146435b10
This seems to confirm my suspicion that self.textDocumentProxy
is being de-allocated.