Database created with Core Data in Swift

0

I need to create an app that is a form with basic data (name, age, email, etc) and save the data for access later, but save it in the tableView, create the database file or worksheet. I saw that CoreData and Realm generated a DB file.

Can you tell me how to access this file, or how to create it, if this is not done automatically by importing CoreData into the project?

I already have an app with CoreData deployed and that saves notes that I write the lists in a tablView, however I need to change them to a form and generate that file in DB format to backup the data.

Thank you very much!

    
asked by anonymous 22.05.2017 / 17:44

1 answer

0

So both Realm and CoreData create a file in the App directory:

~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Data/Application/[AppID]/Documents/

In this directory you can access .db from your database.

To access this directory simply access it through NSFileManager:

let documents = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)

This will return a list of directories, however you just need to get the first one, after that just list the files and get the one you want.

I really enjoy using CoreData but I suggest you use Realm for simplicity and for being quick to work.

If you use realm this lib to back it up to iCloud Drive.

I hope I have helped you = D

    
24.05.2017 / 19:57