Giter Club home page Giter Club logo

Comments (7)

groue avatar groue commented on May 18, 2024

Hello @mtissington

There are two ways to use the inDatabase method:

// Without any return value
dbQueue.inDatabase { db in
    // do some stuff
}

// With a return value
let value = dbQueue.inDatabase { db in
    return ... // return some stuff
}

In your case, you return a value, but don't use it outside: the poor Swift compiler infers that the inDatabase call should both have a value (returned from inside), and have no value (since nothing is consumed), and collapses. I tend to think it's a Swift bug.

The fix is not to return anything, or to use the returned value.

Since you're the second person who asks that question, I think I should at least update the FAQ ;-)

from grdb.swift.

groue avatar groue commented on May 18, 2024

@mtissington, I've just been bitten in an unexpected way myself. Sometimes you also have to explicitly declare the type of the returned value:

// Variant 1
let value: MyType = dbQueue.inDatabase { db in
    return ...
}

// Variant 2
let value = dbQueue.inDatabase { db -> MyType in
    return ...
}

I have to do something about this: I reopen this issue.

from grdb.swift.

mtissington avatar mtissington commented on May 18, 2024

as an fyi i like how you have packaged this all up, for the most part it works quick and is easy to us. thanks!

from grdb.swift.

groue avatar groue commented on May 18, 2024

@mtissington That's the best thing a library writer can read 😄 Happy GRDB!

from grdb.swift.

groue avatar groue commented on May 18, 2024

Little update: the problem is still there in Swift 3, and I could not find any workaround. At least I have enough matter for a bug report on http://bugs.swift.org.

from grdb.swift.

groue avatar groue commented on May 18, 2024

Swift issue created: https://bugs.swift.org/browse/SR-1570

from grdb.swift.

groue avatar groue commented on May 18, 2024

@mtissington I close this issue: there's nothing I can do but waiting for SR-1570 to be fixed. I hope the FAQ will help other users. Thanks for the report!

from grdb.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.