GithubHelp home page GithubHelp logo

Comments (4)

roanutil avatar roanutil commented on August 17, 2024

Adam

Thank you for the question. For simplicity, the tests and README do make use of the viewContext. However, it would be best if at least the tests set a better example by using a private context in the repository.

I've pushed a branch that makes this change.
https://github.com/roanutil/CoreDataRepository/tree/non-main-queue
Please take a look and let me know if this helps.

When making changes to Core Data through the repository, you should NOT have to directly interact with a context or wrap any work in a perform or performAndWait closure. In the tests I do it manually sometimes to avoid testing the repository with the repository itself.

Making this change did reveal a bug where the repository internally did not wrap a save on the parent context within a performAndWait closure. So, that just goes to show what happens when we take shortcuts on tests.

Andrew

from coredatarepository.

oco-adam avatar oco-adam commented on August 17, 2024

Hi Andrew,

Thanks very much for looking in to this.

Yes, the changes you have made to https://github.com/roanutil/CoreDataRepository/tree/non-main-queue help a lot.

By looking at Tests/CoreDataRepositoryTests/CoreDataXCTestCase I can get an idea as to how you intend on setting up a repository for use in the background - thanks!

However, in my opinion these details are really important, if not core to this project's value and it took me a few mins of digging around to find and digest them. So it might be an idea to include this setup in a small section in the readme if possible.

For example, a short section just before the CRUD section of the readme could explain how to set it up the repo on a background queue and therefore the CRUD section could then clarify how to use it on a background queue (i.e. that you don't need to worry about performAndWait etc, which I think is a real advantage of using this library btw!). E.g.

Setting up a Repository on a Background Queue

let backgroundQueue = DispatchQueue(label: "background", qos: .userInitiated)
  var repositoryContext: NSManagedObjectContext?
  backgroundQueue.sync {
       repositoryContext = container.newBackgroundContext()
       repositoryContext.automaticallyMergesChangesFromParent = true
  }
  let repository = CoreDataRepository(context: try repositoryContext)

CRUD

...

I think that what you've done here is really great, but could potentially reach more people by making this aspect a little clearer and easier to find - please let me know your thoughts on this.

Thanks again,
Adam

from coredatarepository.

roanutil avatar roanutil commented on August 17, 2024

Would you mind making a PR with the README changes you would like to see? I think those are reasonable changes but it would be easier to review a PR than try to collaborate in an issue.

from coredatarepository.

roanutil avatar roanutil commented on August 17, 2024

Feel free to re-open if you want to continue on this

from coredatarepository.

Related Issues (3)

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.