All Projects → srmds → Coredata Crud Swift 5.0 Example

srmds / Coredata Crud Swift 5.0 Example

Licence: mit
Swift 5.0 Example project that exposes the usage of Core Data to create Entities and to persist to a SQLite Datastore

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Coredata Crud Swift 5.0 Example

Whatsnew
Showcase new features after an app update similar to Pages, Numbers and Keynote.
Stars: ✭ 1,512 (+863.06%)
Mutual labels:  ios11
Swift Articles
Monthly Series - Top 10 Angular Articles
Stars: ✭ 139 (-11.46%)
Mutual labels:  ios11
Cloudcore
Framework that enables syncing between iCloud (CloudKit) and Core Data
Stars: ✭ 146 (-7.01%)
Mutual labels:  coredata
Arkit Floorislava
Basic ARKit example that detects planes and makes them lava.
Stars: ✭ 120 (-23.57%)
Mutual labels:  ios11
Facelandmarksdetection
Finds facial features such as face contour, eyes, mouth and nose in an image.
Stars: ✭ 130 (-17.2%)
Mutual labels:  ios11
Coredataplaygrounds
Exploring Core Data through Swift playgrounds
Stars: ✭ 139 (-11.46%)
Mutual labels:  coredata
Exermote
Using Machine Learning to predict the type of exercise from movement data
Stars: ✭ 108 (-31.21%)
Mutual labels:  ios11
Cs193p Fall 2017 Demo
Stanford CS193P Fall 2017 Demo
Stars: ✭ 157 (+0%)
Mutual labels:  ios11
Swiftui Core Data Test
Sample program to demonstrate how CoreData can be used with SwiftUI.
Stars: ✭ 135 (-14.01%)
Mutual labels:  coredata
Gestureai Coreml Ios
Hand-gesture recognition on iOS app using CoreML
Stars: ✭ 145 (-7.64%)
Mutual labels:  ios11
Arkit Unity3d
Access ARKit features like world-tracking, live video rendering, plane estimation and updates, hit-testing API, ambient light estimation, and raw point cloud data.
Stars: ✭ 124 (-21.02%)
Mutual labels:  ios11
Widgetexamples
A demo project showcasing different types of Widgets created with SwiftUI and WidgetKit.
Stars: ✭ 125 (-20.38%)
Mutual labels:  coredata
Cs193p Fall 2017
These are the lectures, slides, reading assignments, and problem sets for the Developing Apps for iOS 11 with Swift 4 CS193p course offered at the Stanford School of Engineering and available on iTunes U.
Stars: ✭ 141 (-10.19%)
Mutual labels:  ios11
Arplayer
Playback videos using ARKit and AVFoundation.
Stars: ✭ 117 (-25.48%)
Mutual labels:  ios11
Amazing Swift Ui 2019
23 Amazing iOS UI Libraries written in Swift for the Past Year (v.2019)
Stars: ✭ 147 (-6.37%)
Mutual labels:  ios11
Dictionaryplusplus
Dictionary++ is a simple interface to iOS's system dictionary.
Stars: ✭ 112 (-28.66%)
Mutual labels:  coredata
Mnist draw
This is a sample project demonstrating the use of Keras (Tensorflow) for the training of a MNIST model for handwriting recognition using CoreML on iOS 11 for inference.
Stars: ✭ 139 (-11.46%)
Mutual labels:  ios11
Justpersist
JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box. It also allows you to migrate to any other persistence framework with minimal effort.
Stars: ✭ 157 (+0%)
Mutual labels:  coredata
Styletransfer Ios
Stars: ✭ 155 (-1.27%)
Mutual labels:  ios11
Awesome Ml
Discover, download, compile & launch different image processing & style transfer CoreML models on iOS.
Stars: ✭ 142 (-9.55%)
Mutual labels:  ios11

CoreData-CRUD-Swift-5.0-iOS-example

Swift 5.0 - A (very simple) example project that exposes the usage of CoreData to create entities and to persist to a SQLite Datastore.

This app demonstrates Core Data and persistent storage, by reading Event data from both, locally and remotely retrieved JSON file / response, creates and stores those Events in a SQLite datastore. It is possible to do single and batch updates, deletions, retrieving and filtering on stored Events.

Note: If you are considering to use Core Data in an app meant for production, it is worth to investigate Realm, which is a mobile platform and a replacement for SQLite & Core Data, for both Android & iOS.

screenshotOverview

Prerequisites

iOS

Tested on:

  • iOS9
  • iOS10
  • iOS11
  • iOS12

iPhone

Tested on:

  • iPhone 6
  • iPhone 6s
  • iPhone 7
  • iPhone 8
  • iPhone Xr

The objective

for this project is to learn to:

  • Use Core Data to create Entities and to persist Entities to a SQLite datastore

  • Help others understand and use Core Data with simple, yet concrete examples, on the usage of Core Data and persistent store

location of SQLite database

In order to inspect persisted events you can use for example a SQLite database browser to view persisted entries: https://sqlitebrowser.org

The actual path of the SQLite database file will be shown in the Xcode console logger. For example:

/Users/<name>/Library/Developer/CoreSimulator/Devices/<device-uuid>/data/Containers/Data/Application/<application-uuid>/Documents

  1. Select and copy the path that is logged in the Xcode Console (In XCode -> View -> Debug Area -> Activate Console) to SQLite database file.

  2. Go to MacOS Finder, press:SHIFT + CMD + G and paste the logged path to the SQLite database file and click: OK

  3. Finally open the SQLite database file with, for example: SQLite browser

Note: this example project is non-exhaustive.

Contributions

Do you have questions or want to help? Enhancements and/or fixes and suggestions are welcome! Just drop create an issue and/or pull requests.

Model

A model represents the entity that can be used to store in the datastore. The Event Entity/ Model has the following model attributes:

class Event: NSManagedObject {
    @NSManaged var title: String
    @NSManaged var date: NSDate
    @NSManaged var venue: String
    @NSManaged var city: String
    @NSManaged var country: String
    @NSManaged var attendees: AnyObject
    @NSManaged var fb_url: AnyObject
    @NSManaged var ticket_url: AnyObject
    @NSManaged var eventId: String
}

The AnyObject type in this example are non-standard persistent attributes that are not supported directly in Core Data. The AnyObject, as the name suggests, can therefore be for example: an Array or NSURL, or any other objecttype.

Core Data API

This application utilises the Core Data stack concurrently to locally persist data. Below you will find an overview of: how the Core Data stack is implemented and utilised within the application.

CoreData Thread confinement

Thread confinement

You can see that there are three layers used, this is to provide true concurrency and also utilise thread confinement.

The minions* workers are the workers in the EventAPI that save each parsed and prepared NSManagedObject within it's own Thread. Eventually when all NSManagedObjects are stored within the thread confined context, the EventAPI calls the MainContext via the PersistenceManager, which in turn will call ContextManager and cause the minions to merge / synchronize with the MainContext and and with the Master application context, which finally calls the DataStore Coordinator to actually store the NSManagedObjects to the datastore.

More info on concurrency

Event API

The Event API is the interface where a view controller directly communicates to. The Event API exposes several endpoints to a view controller to Create, Read, Update, Delete Events.

Open up Xcode, and open the project, and open the EventAPI.swift file. Then click on ^6, thus control + 6, this will open up an overview of several CRUD methods used, and click on the method of interest, to see it's implementation.

*No copyright infringement intended.

More info

More Core Data basics can be found here

The MIT License (MIT)

Copyright (c) 2016 - srmds

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].