# A C function pointer cannot be formed from a local function that captures context on Swift Package

**URL:** <https://forums.swift.org/t/a-c-function-pointer-cannot-be-formed-from-a-local-function-that-captures-context-on-swift-package/9388>\
**Category:** Using Swift\
**Created:** [January 31, 2018, 11:50am UTC](https://forums.swift.org/t/a-c-function-pointer-cannot-be-formed-from-a-local-function-that-captures-context-on-swift-package/9388 "2018-01-31T11:50:54Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [January 31, 2018, 4:32pm UTC](https://forums.swift.org/t/a-c-function-pointer-cannot-be-formed-from-a-local-function-that-captures-context-on-swift-package/9388/6 "2018-01-31T16:32:27Z")

</div>

Ah! Well, if your goal is for `newMessageHandler` to capture context, then you will _have_ to put it in a Swift type, rather than a C type. Go back to your old version with the `UserData` class and `Unmanaged`, and make sure to annotate `cHandler` with `@convention(c)`.

---

_[View the full topic](https://forums.swift.org/t/a-c-function-pointer-cannot-be-formed-from-a-local-function-that-captures-context-on-swift-package/9388)._
