• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C callbacks with NSNotificationCenter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C callbacks with NSNotificationCenter?


  • Subject: Re: C callbacks with NSNotificationCenter?
  • From: Andreas Falkenhahn <email@hidden>
  • Date: Wed, 07 Sep 2016 19:44:29 +0200

Hi Fritz,

On 07.09.2016 at 18:35 Fritz Anderson wrote:


>> On 7 Sep 2016, at 11:09 AM, Andreas Falkenhahn <email@hidden> wrote:

>> As a C programmer I'm trying to avoid Objective C whenever and wherever possible.
>> The good thing is that I can do most interaction with Cocoa from normal C functions.
>> I only had to write very few classes. Most of the Cocoa stuff can be done
>> from normal C functions just fine.

> I shall little more than observe that “C programmer” is an odd
> definition of a professional identity. To my ear (not knowing you
> well), it’s like saying “I drink liquids.”

> I kind of get it, as I claim an identity as an Apple-platform
> developer, but I’d argue it describes a different kind of expertise,
> and in my case a strong political tendency. Drawing the line at C surprises me.

> Now let me actually respond to what you wrote.

>> Still, I'm wondering: Is it also possible to have NSNotificationCenter call
>> a C function for me whenever the notification triggers? Can this somehow
>> be achieved or am I forced to use full Objective C here?

> NSNotificationCenter has a method in the form of addObserver: ...
> using:, which takes a block. Blocks can contain pure C.

Ok, blocks look like they could do the trick. But how can I access variables
from inside such blocks? i.e.

    void iAmACFunc(void *dataptr)
    {
        printf("Trigger for %p\n", dataptr);
    }

-------------------------------------------------------------

    void *IMPORTANT_DATA_PTR = ....;

    [[NSNotificationCenter defaultCenter]
      addObserverForNotificationName:AVPlayerItemDidPlayToEndTimeNotification
                              object:playerItem
                               queue:[NSOperationQueue mainQueue]
                               block:^(NSNotification *notification) {
                                  iAmACFunc(IMPORTANT_DATA_PTR);  // call C func, pass important data
                               }];

-------------------------------------------------------------

How can I access "IMPORTANT_DATA_PTR" from within the block above?

--
Best regards,
 Andreas Falkenhahn                            mailto:email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: C callbacks with NSNotificationCenter?
      • From: Graham Cox <email@hidden>
References: 
 >C callbacks with NSNotificationCenter? (From: Andreas Falkenhahn <email@hidden>)
 >Re: C callbacks with NSNotificationCenter? (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: Unusual Conditional Formatting
  • Next by Date: Re: C callbacks with NSNotificationCenter?
  • Previous by thread: Re: C callbacks with NSNotificationCenter?
  • Next by thread: Re: C callbacks with NSNotificationCenter?
  • Index(es):
    • Date
    • Thread