Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Crash DATAStack.backgroundContextaDidSave #111

Closed
hei9gag opened this issue Jan 24, 2018 · 5 comments
Closed

Crash DATAStack.backgroundContextaDidSave #111

hei9gag opened this issue Jan 24, 2018 · 5 comments

Comments

@hei9gag
Copy link

hei9gag commented Jan 24, 2018

Hi, I got some crashes when using DATAStack and Instabug together. It seems the crash related to DATAStack listen to all NSManagedObjectContext notification thrown by other parties. And cause bad memory address. Do you have any ideas how to fix it? Many thanks.

screen shot 2018-01-24 at 10 02 18 am

@3lvis
Copy link
Owner

3lvis commented Jan 25, 2018

Hi @hei9gag,

I'm not sure what's going on here. DATAStack doesn't listen to all the notifications. It listens to notifications for the NSManagedContext that's been saved.

For example here

    @objc public lazy var mainContext: NSManagedObjectContext = {
        let context = //...
        //....

        NotificationCenter.default.addObserver(self, selector: #selector(DATAStack.mainContextDidSave(_:)), name: .NSManagedObjectContextDidSave, object: context)

        return context
    }()

If you see in NotificationCenter.default.addObserver we pass the context as the object. This means that only notifications for this context will be received.

https://developer.apple.com/documentation/foundation/nsnotificationcenter/1415360-addobserver?language=objc

screen shot 2018-01-25 at 10 36 05

Not sure what Instabug is doing internally.

@hei9gag
Copy link
Author

hei9gag commented Jan 26, 2018

Thanks @3lvis I have also checked the code and the notification part looks good to me too. I will check with Instabug again.

@hei9gag hei9gag closed this as completed Jan 26, 2018
@3lvis
Copy link
Owner

3lvis commented Jan 26, 2018

No problem, have a nice day and good luck!

@3lvis
Copy link
Owner

3lvis commented Jan 31, 2018

This might be related #112

@hei9gag
Copy link
Author

hei9gag commented Feb 1, 2018

Thanks it fixed the crash problem. Learn something new again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants