BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

Is Core Data always using an SQLite DB behind the scenes? - Project 11

Forums > SwiftUI

Hi all,

Is Core Data always using an SQLite DB behind the scenes?

Should I be able to find a .sqlite file somewhere that stores the books? Or is persisted in another way?

I am working on project 11 and was curious about this.

I see

    // MARK: - Core Data Saving support

    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }

take care Bill

4      

Yes, there is always a SQLite behind it. You can find it in the documents folder. As with every new build a new documents folder is created on the simulator it's getting quite cumbersome to search it manually everytime.

https://www.codefellows.org/blog/core-data-and-database-browser-for-sqlite/

Create a function in your app and print it out. F.e. on app start.

func getCoreDataDBPath() {
        let path = FileManager
            .default
            .urls(for: .applicationSupportDirectory, in: .userDomainMask)
            .last?
            .absoluteString
            .replacingOccurrences(of: "file://", with: "")
            .removingPercentEncoding

        print("Core Data DB Path :: \(path ?? "Not found")")
    }

Or you could use the neat little app: https://apps.apple.com/us/app/core-data-lab/id1460684638?mt=12

4      

To be precise, it doesn't have to be a SQLite database, there's other possibilities: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/PersistentStoreFeatures.html

Without any numbers to base this on, I'd say most Core Data setups are backed by SQLite.

4      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.