Coder Social home page Coder Social logo

earthquakeswiftdata's Introduction

Loading and displaying a large data feed with SwiftData

This is an example inspired by the original Core Data sample but using SwiftData

It loads the monthly earthquake list, creates a secondary context on a background thread with autosave off. Then proceeds to process the batch by insertign all elements and then saving the context.

This is not as efficient as the strategy of using context merging, but does work albeit with a large delay when saving the context. I have not yet figured out how to fix that short of using 3rd pary packages that enable context merging. But thats besides the point of doing this using SwiftData :)

The strategy is to first fetch the data, then decode each element iteratively skipping elements with missing properties (implemented in the decodable data transfer object), appending them to a local array. Once all the elements are decoded they are imported into SwiftData using the background context. When all elements are inserted in the background context it is saved and the main context then picks up the change and updates the UI.

earthquakeswiftdata's People

Watchers

Jens Troest avatar

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.