Skip to content

iOS-Extension-Demo in Swift #2

@ghost

Description

Hi,
Thanks for your sharing ^^
I have an ask about your last commit : "Add change notifications based on the Darwin notification center."
In DemoManager, there is this C function in an ObjC Class :

void sharedDataChangedCallback(CFNotificationCenterRef postingCenter,
                               void * observer,
                               CFStringRef name,
                               void const * object,
                               CFDictionaryRef userInfo)
{
    // Springboard from Darwin notification center to NSNotificationCenter.
    // Note that most of the received arguments are NULL with the Darwin notification center.
    [[NSNotificationCenter defaultCenter] postNotificationName:kDemoNotesSaveByAppNotification object:[DemoNoteManager sharedManager]];
}

In my Swift class, always this same C function :

func sharedDataChangedCallback(center: CFNotificationCenterRef,
                             observer: AnyObject,
                                 name: CFString,
                               object: AnyObject,
                             userInfo: CFDictionaryRef)
{   NSNotificationCenter.defaultCenter().postNotificationName(kDemoNotesSaveByAppNotification , object: CoreDataStore.sharedInstance)
}

When I call CFNotificationCenterAddObserver() in startObservingChangeNotifications() (in DemoManager) like that :

CFNotificationCenterAddObserver(center, nil, sharedDataChangedCallback, self.observingSaveNotificationName() as CFString!, nil, CFNotificationSuspensionBehavior.DeliverImmediately)

I have got this error : error

My method sharedDataChangedCallbackin Swift isn't correct but I don't know how to solve my issue. Could you help me about that ?

Morever, you have never called "stopObservingChangeNotifications()" in DemoManager. In MastViewController, I think this code misses :

-(void) deinit {
    DemoNoteManager *sharedManager = [DemoNoteManager sharedManager];
    [sharedManager stopObservingChangeNotifications];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions