core-data | Sample code for the objc.io Core Data book | Learning library

 by   objcio Swift Version: Current License: MIT

kandi X-RAY | core-data Summary

kandi X-RAY | core-data Summary

core-data is a Swift library typically used in Tutorial, Learning applications. core-data has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

This repository contains the sample code of our Core Data book:.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              core-data has a low active ecosystem.
              It has 729 star(s) with 179 fork(s). There are 62 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 27 open issues and 19 have been closed. On average issues are closed in 66 days. There are 9 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of core-data is current.

            kandi-Quality Quality

              core-data has no bugs reported.

            kandi-Security Security

              core-data has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              core-data is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              core-data releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of core-data
            Get all kandi verified functions for this library.

            core-data Key Features

            No Key Features are available at this moment for core-data.

            core-data Examples and Code Snippets

            No Code Snippets are available at this moment for core-data.

            Community Discussions

            QUESTION

            How to apply EF Core migrations if you should not use MigrateAsync() for production environments?
            Asked 2021-Jun-08 at 11:38

            I created a new .Net 5 project and want to use EF Core. I autogenerated multiple migration.cs files using

            dotnet ef migrations add MyMigration

            and want to apply them (for development and production). I know about the MigrateAsync method so I read about how to call this method on startup

            https://andrewlock.net/running-async-tasks-on-app-startup-in-asp-net-core-part-1/

            but everywhere I read that this method should not be used for production since those migrations won't be executed in a single transaction (no rollback on errors).

            Unfortunately there are not many resources on how to do it regardless of the environment, I found this article

            https://www.thereformedprogrammer.net/handling-entity-framework-core-database-migrations-in-production-part-2

            One option could be a console app calling the migrations

            https://www.thereformedprogrammer.net/handling-entity-framework-core-database-migrations-in-production-part-2/#1b-calling-context-database-migrate-via-a-console-app-or-admin-command

            but I wasn't able to understand the difference for this approach because it's not solving the transactional problem?

            What are best practises to apply migrations during development/production?

            • After autogenerating migrations I'm a big fan of simplicity, does dotnet ef database update the job and I don't need to work with additional tools?

            • Create a console app, generate .sql files from the migrations, install DbUp and use it for the migration part?

            ...

            ANSWER

            Answered 2021-Jun-01 at 23:42

            What works best heavily depends on how deployment pipeline works - how many environments are there before production, release cycle, what parts of deployment are automated. There are no universal "best practices" - each way of handling migrations has its own set of tradeoff to be concious about. Pick upgrade procedure according to what your needs and expectations are.

            When setting up EF Core migrations for a mid-sized project (around 70 tables), I tried out few potential approaches. My observations from the process and what worked out in the end:

            1. You want to get a migration SQL somewhere between changing your models and deploying to production, if only to look at it in case there are any breaking changes that may cause issues on rollback. We decided on having migrations directly in project with dbcontext, and have a migration script (using dotnet ef migrations script --idempotent) be generated for every build that can potentially be deployed to any environment - in our case, a CI step for each push to trunk or release branch.
            2. Putting migration SQL in version control and treating SQL as a source of truth in regards to database structure gives an ability to manually modify scripts when you want to keep some columns for backup or backwards compatibility purposes. Another option would be to consider your data model as a reference for database schema and treat migration SQL as intermediate step that is not preserved, which makes it easier to automate whole process, but requires you to handle special cases directly in your datamodel.
            3. Using --idempotent flag when generating migration script gives you a script you can reapply to a database schema regardless of what schema version it was at, having it execute only steps that were not yet executed. This means you can reapply same migration script to already migrated database without breaking schema. If you have different versions of your application running in parallel in separate environments (development, staging and production environment), it can save issues with tracking manually what migration scripts version you need to apply and in what order.
            4. When you have migration SQL, you can use native for your database tools in order to apply them to target environment - such as sqlcmd for SQL Server, psql for postgres. This also has a benefit of having separate user with higher privileges (schema modification) handle migrations, while your application works on limited privileges, that often can't touch the schema.
            5. Applying database migrations is part of application deployment, not application startup - if you have deployment automation of some sorts, it's probably the best place to put executing migrations against target database, again - database native client is a good alternative to DbUp, pick whichever you prefer. Separating migrations from application startup also gives you ability to run an application against mismatched, but still compatible database schema - which comes handy when e.g. you're doing rollout deployments.
            6. Most problems with schema upgrades come from breaking schema compatibility between versions - avoiding that requires being concious about backwards/forward compatibility when working on data model and splitting breaking changes into separate versions that keep at least single step of backwards/forwards compatibility - whether you need it depends on your project, it's something you should decide on. We run full integration test suite for previous version against current database schema and for current version against previous database schema to make sure no breaking changes are introduced between two subsequent versions - any deployment that moves multiple versions will roll out migrations one by one, with assumption that migration script or application startup can include data transformation from old to new model.

            To sum up: generating migration SQL and using either native tools or DbUp on version deploy gives you a degree of manual control over migration process, and ease of use can be achieved by automating your deployment process. For development purposes, you may as well add automatic migrations on application startup, preferably applied only if environment is set to Development - as long as every person on a team has its own development database (local SQL, personal on a shared server, filedb if you use SQL) there are no conflicts to worry about.

            Source https://stackoverflow.com/questions/67761614

            QUESTION

            Delimiter in VBA,Macros
            Asked 2021-Jun-07 at 19:16

            Need to split the 3rd row and have it in the below xml format.

            My Excel data:

            ID EMail UserGroupID Aravind Aravind@gmail.com Sports(12-34) Aravind2 Aravind2@gmail.com Sports(3-24-5),Health(5-675-85), Education(57-85-96)

            My XML data:

            ...

            ANSWER

            Answered 2021-Jun-07 at 19:16

            Try something like this:

            Source https://stackoverflow.com/questions/67876729

            QUESTION

            How can I use relationship in ForEach in CoreData using SwiftUI?
            Asked 2021-May-02 at 13:44

            The problem has been solved by 'hackingwithswift' website

            Just follow the steps on the link! "https://www.hackingwithswift.com/books/ios-swiftui/one-to-many-relationships-with-core-data-swiftui-and-fetchrequest"

            original ask

            I would like to use elements of [relationship]
            But whatever I try, it doesn't work..
            There is something, what I missed and, sadly I don't know what that would be until now :/

            First of all, I want to show my core data model and code.

            Core Data Model Image

            Entity: Page, Attribute: name(String), relationship: toCard
            Entity: Card, Attribute: title(String), price(Double), relationship: toPage

            Scenario: Page has multiple cards
            One to Many (One page to many cards)

            ...

            ANSWER

            Answered 2021-May-02 at 13:44

            I solved this problem with help from this awesome 'hackingwithswift' website! Just follow the steps on the link!

            https://www.hackingwithswift.com/books/ios-swiftui/one-to-many-relationships-with-core-data-swiftui-and-fetchrequest

            Edited:

            1. Goto .xcdatamodeld file

            2. Click Entity -> Class -> Codezen to Manual/None

            3. Editor -> Create NSManagedObject Subclass

            4. Add in Page+CoreDataProperties.swift

            Source https://stackoverflow.com/questions/67297561

            QUESTION

            Secure Coding Measurement Classes in Core Data, NSValueTransformers
            Asked 2021-Apr-20 at 20:24

            I have an app that heavily uses Measurements. It is written in SwiftUI/iOS 14. I persist the data in a Core Data database. The app is working fine, until I try to implement secure coding. I made a sample app to strip everything away except the basics. It is based off of Xcode's default Core Data app with few changes. Again, I can save my measurement fine until I try to use secure coding.

            The xddatamodel, as well as the errors, is as follows:

            I am using a manual codegen for the Entity and it looks like this:

            ...

            ANSWER

            Answered 2021-Apr-20 at 20:24

            Thanks to @LeoDabus I was finally able to hammer this out. The key is to transform the Swift Measurements into NSMeasurement and use NSMeasurement in Core Data. You will need to set your custom class to an NSMeasurement. Your transformer will be a custom value transformer. I called mine NSMeasurementValueTransformer. Your .xcdatamodeld will look like this:

            I defined my custom value transformer as:

            Source https://stackoverflow.com/questions/67113930

            QUESTION

            Core Data doesn't update related objects
            Asked 2021-Apr-14 at 04:49

            I have a class A that has a "to many" relationship with B. A and its Bs are fetched from a REST endpoint, we use this approach to create the objects.

            A has a unique ID and some other properties (not shown in the example). B has an ID (bID) that is unique when combined with A, and a relationship to A called a. For A the constraint is "uniqueID". For B, the constraint is "a, bID" - we want each B to only exist for each combination of A and bID. The delete rule for A to its Bs is "Cascade". The merge policy for the context and all child contexts is NSOverwriteMergePolicy.

            The code looks something like this:

            ...

            ANSWER

            Answered 2021-Apr-14 at 04:49

            I'm using the following extension to solve this problem:

            Source https://stackoverflow.com/questions/67044602

            QUESTION

            SwiftUI: Group and Sum by Core Data Attribute
            Asked 2021-Apr-13 at 22:16

            The question is this: how do you group Core Data objects by attribute and then perform simple calculations (let's say, sum) on them?

            I've found a few similar answers for this (like this one), but none seem conclusive and all are geared up towards Swift (whereas I am working on SwiftUI).

            For example, I have a Core Data model that looks like this:

            ...

            ANSWER

            Answered 2021-Apr-13 at 22:16

            You should not have brackets around the i in [i] in. Brackets like that capture a value, but you don't have a variable to capture -- you're just getting a parameter for the closure.

            Source https://stackoverflow.com/questions/67082965

            QUESTION

            CoreData Model within Swift Package
            Asked 2021-Apr-07 at 17:27

            I am trying to put a CoreData model into a Swift Package to extract my model code / classes from my main codebase.

            I have done the following to recreate the issue I'm having from scratch:

            • Create a new swift package called SampleModelPackage (File -> New -> Swift Package)
            • Created a Core Data Model Definition File (Create File -> New -> File | iOS -> Core Data -> Data Model)
            • Saved it in the Sources/SampleModelPackage directory alongside the auto-generated SampleModelPackage.swift

            Now - when I attempt to open the Model.xcdatamodelId file in Xcode, it just shows me a "Version" icon (see screenshot), whereas creating a Core Data Model file in a Project or Framework will allow me to edit the model.

            The second / follow up question would be how would I then extend the code-gem'd model files as normal? And how would I load that model definition (normally I would use a Bundle ID and the model file name)

            I have tried adding the model file to the resources array of the Package.swift file (using .process and using .copy) as described on this page: https://developer.apple.com/documentation/swift_packages/bundling_resources_with_a_swift_package

            Or more generally, is this even possible? (this article https://ishabazz.dev/blog/2020/7/5/using-core-data-with-swift-package-manager seems to imply that packaging core data models like this is possible)

            (I am using Xcode 12.4)

            ...

            ANSWER

            Answered 2021-Apr-07 at 17:27

            You need to create your Core Data model in an ordinary Xcode project, then you can create your package and drag the model to it. (This is also what was done in the linked article if you look carefully even though it was not clearly described).

            I believe the the best thing is to manually generate the source code files for your entities and add them to your package. You load the model using Bundle but instead of Bundle.main you use Bundle.module

            Source https://stackoverflow.com/questions/66990642

            QUESTION

            Why is my list of parent items growing without adding items
            Asked 2021-Mar-25 at 14:34

            I have a simple core-data/swiftui test app with 2 entities. 1: Item entity with a simple text and timestamp attributes. And a one-to-one relationship to an Editor entity. 2: editor entity with a name attribute and a one-to-many relationship to Item. In the item view I want to pick an editor from a list of stored Editors. However when I update the view (i.e. adding text to the text attribute), the list of editors to pick from grows with new and empty editor objects.

            ...

            ANSWER

            Answered 2021-Mar-25 at 14:34

            You are creating an Editor every time the ContentView body is reloaded.

            Comment out this code and it won't happen anymore. How to fix it? Take persistence code out of any View struct it doesn't belong there.

            Put it into a class ViewModel or a Manager and just call methods/ pass variables with the View actions.

            Source https://stackoverflow.com/questions/66799079

            QUESTION

            Select and Delete Core Data entities in SwiftUI List View on macOS
            Asked 2021-Feb-17 at 00:23

            I am a newbie to SwiftUI but making reasonable progress. I am using the latest version of Xcode 12.4 and running BigSur 11.2.1. I am at the stage where I want to use core-data but have run into an issue that I can't find a fix.

            When I create the basic Xcode project I select App and macOS as the template Then I select Interface - SwiftUI, Life Cycle - SwiftUI App, Language - Swift and select Use Core Data

            A new project is created and Builds and Runs without any issues. In the window that appears I can add a new item (a datestamp) by simply clicking the + Button on the top bar. So far so good. This is all vanilla apple code.

            Where I am stuck :- The List - ForEach View in the ContentView won't allow any of the Entities (items) to be selected by clicking and therefore I can't find a way to delete an entry.

            If I replace the Entities with an array of Text items then I can select them and delete them by using @State var selectKeeper = Set() with a selection: $selectKeeper in the List View.

            Can someone please explain how to do it?

            This is the vanilla code for the content view.

            ...

            ANSWER

            Answered 2021-Feb-17 at 00:23

            You should add EditButton() and probably wrap all of this in NavitagionView might give you what you are looking for:

            Source https://stackoverflow.com/questions/66195969

            QUESTION

            In a SwiftUI lifecycle app, where exactly should I register a CoreData transformerValue?
            Asked 2021-Jan-09 at 17:34

            I'm trying to follow this tutorial:

            https://www.avanderlee.com/swift/valuetransformer-core-data/

            But I'm stumped on where (and how!) exactly to use

            ...

            ANSWER

            Answered 2021-Jan-09 at 17:34

            Put it into init, like

            Source https://stackoverflow.com/questions/65645568

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install core-data

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/objcio/core-data.git

          • CLI

            gh repo clone objcio/core-data

          • sshUrl

            git@github.com:objcio/core-data.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link