nicklockwood/FXNotifications

FXNotifications possible conflict with GRDB

Closed this issue · 4 comments

Hello, I got referred here from GRDB.

Referencing issue: groue/GRDB.swift#42

This commit introduces deinit for DatabaseQueue.
groue/GRDB.swift@005c4de

Which gives me the following crash on deinit:

*** NSForwarding: warning: object 0x7f96e526a550 of class 'GRDB.DatabaseQueue' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[GRDB.DatabaseQueue FXNotifications_observers:]

Perhaps DatabaseQueue should also inherit from NSObject?

Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'GRDB.swift'
pod 'FXNotifications'

ViewController.swift:

import UIKit
import FXNotifications
import GRDB

class ViewController: UIViewController {

    var queue = [Int:DatabaseQueue]()

    override func viewDidLoad() {
        super.viewDidLoad()
        queue[1] = DatabaseQueue()
        queue[2] = DatabaseQueue()
        queue[1] = nil
        queue[2] = nil
    }
}

Making DatabaseQueue a subclass of NSObject seems to fix the crash bug.

groue commented

Hello,

I'm the author of GRDB, and I could look at this problem before advising @ptseng opening this issue in this repository.

The DatabaseQueue class seen above is a Swift class that does not inherit from NSObject, and yet uses NSNotificationCenter (with @objc methods as notification callbacks). In its deinit method, it unregisters from NSNotificationCenter, as should do any object that has to run before iOS9. And everything is OK, until FXNotifications comes in, swizzles -[NSNotificationCenter removeObserver:], and crashes:

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

You swizzling of -[NSNotificationCenter removeObserver:] assumes the observer is an NSObject instance. And when it is not.... @ptseng's application crashes.

Thanks for bringing this to my attention. This should be fixed in version 1.1.1. Let me know if not.

@nicklockwood Confirmed it is fixed. Thank you.