How to allocate -> send -> receive -> cast -> deallocate UnsafeRawPointer from extension to app?

前端 未结 1 1506
你的背包
你的背包 2021-01-24 02:09

I am new in UnsafeRawPointer. As I got I need to allocate unsafe memory in my extension and send pointer to my app where has to cast and release it. Below is a sk

相关标签:
1条回答
  • 2021-01-24 02:50

    Thanks @MartinR, I got all answers on my questions.

    We can't send an object though CFNotificationCenterPostNotification so we need to use Darwin and UserDefaults(suitename:) combination.

    Schema

    1. Add the CFNotificationCenterAddObserver observer in the app code
    2. Save sending object in UserDefaults(suitename:)
    3. Send the didObjectChanged notification through CFNotificationCenterPostNotification code
    4. Catch didObjectChanged notification in CFNotificationCallback in the app code
    5. Read sending object from UserDefaults(suitename:)

    Off-topic

    Question Why do we use UnsafeRawPointer? sample

    Answer CFNotificationCenterPostNotification is actually a C function, and the callback is also a pure C function. C knows nothing about Swift types or instance pointers. That's why the object parameter is a UnsafeRawPointer (the Swift equivalent of void *).

    0 讨论(0)
提交回复
热议问题