Skip to content

Instantly share code, notes, and snippets.

@lhoward
Created March 7, 2022 01:30
Show Gist options
  • Select an option

  • Save lhoward/c0df244cc737b7e772f1f5866cafe52f to your computer and use it in GitHub Desktop.

Select an option

Save lhoward/c0df244cc737b7e772f1f5866cafe52f to your computer and use it in GitHub Desktop.
SCDynamicStoreCreateWithHandler
#include <SystemConfiguration/SystemConfiguration.h>
#include "SCExtras.h"
static void
__SCDynamicStoreBlockCallBack(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info)
{
void (^block)(SCDynamicStoreRef store, CFArrayRef changedKeys) = info;
block(store, changedKeys);
}
SCDynamicStoreRef
SCDynamicStoreCreateWithHandler(CFAllocatorRef allocator,
CFStringRef name,
void (^block)(SCDynamicStoreRef store, CFArrayRef changedKeys))
{
SCDynamicStoreContext storeContext = {
.version = 0,
.info = block,
.retain = (const void * __nonnull (* __nullable)(const void *))_Block_copy,
.release = _Block_release,
.copyDescription = NULL
};
return SCDynamicStoreCreate(allocator, name, __SCDynamicStoreBlockCallBack, &storeContext);
}
#ifndef SCExtras_h
#define SCExtras_h
#include <SystemConfiguration/SystemConfiguration.h>
CF_IMPLICIT_BRIDGING_ENABLED
CF_ASSUME_NONNULL_BEGIN
_Nullable SCDynamicStoreRef
SCDynamicStoreCreateWithHandler(_Nullable CFAllocatorRef allocator,
_Nonnull CFStringRef name,
void (^_Nonnull block)(_Nonnull SCDynamicStoreRef store, _Nonnull CFArrayRef changedKeys));
CF_ASSUME_NONNULL_END
CF_IMPLICIT_BRIDGING_DISABLED
#endif /* SCExtras_h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment