question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

I 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:closed
  • Created 3 years ago
  • Reactions:22
  • Comments:7

github_iconTop GitHub Comments

7reactions
gazialankuscommented, Aug 1, 2020

It needs the exclamation mark on my end. Without the exclamation mark I get

Argument type 'FlutterPluginRegistrar?' does not conform to expected type 'FlutterPluginRegistrar'
5reactions
Drabunacommented, May 8, 2020

Helpful, thanks! Except you don’t need exclamation mark at the end here:

FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found