Update README for Swift to avoid "A C function pointer can only be formed from a reference to a 'func' or a literal closure" Error
See original GitHub issueI copied the code from the README file into my AppDelegate and got an error saying “A C function pointer can only be formed from a reference to a ‘func’ or a literal closure”. This was due to the fact your are passing the instance method registerPlugins
as an argument into the FlutterDownloaderPlugin.setPluginRegistrantCallback
method. This seems to be due to an issue bridging with Objective C.
Fortunately this stack overflow answer pointed me in the right direction and I was able to solve it by instead passing a closure as an argument like so:
FlutterDownloaderPlugin.setPluginRegistrantCallback { registry in
if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
}
}
The README should be updated so that it works.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:7
Top Results From Across the Web
How to use instance method as callback for function which ...
The callback is a pointer to a C function, and in Swift you can pass only a global function or a closure (which...
Read more >A C function pointer cannot be formed from a local function ...
I am trying to call a Swift callback function inside the C function passed as a parameter to the library call.
Read more >Is it possible to implement c callback function in swift2
When calling a function that takes a function pointer argument, you can pass a top-level Swift function, a closure literal, or
Read more >Nimble - Swift Package Index
There's no easy way to assert that a string contains a particular substring, or that a number is less than or equal to...
Read more >perlfunc - Perl builtin functions
A unary operator generally provides scalar context to its argument, while a list operator may provide either scalar or list contexts for its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It needs the exclamation mark on my end. Without the exclamation mark I get
Helpful, thanks! Except you don’t need exclamation mark at the end here:
FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")
!)