Realm database open file - swift

I am working on my mobile app and with that I have been using Realm Database to store the user data. Further I have made a application for mac that is supposed to be able to open a realm file and display the user data from the file (Yes I know I can use Realm Studio for this, but I want to be able to develop my own application to add some features that my client needs). Does anyone know how I can open a realmfile on an mac app and make the realm code to use data from that file to fill out my tableview?
Thanks!
EDIT: Sorry for my unclear question. What I want is a way for realm database to get use data from a different file than the "default.realm" file. I have tried to see trough the documentation on realm.io but I could not figure it out, hope this cleared things up!

Based on an edit to the question, I believe the question is how to access a Realm file other than default.realm.
Here's one option; suppose you want to call your realm file todo.realm.
func setRealmFile() {
var config = Realm.Configuration()
// Using the default directory, append todo.realm
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("todo.realm")
Realm.Configuration.defaultConfiguration = config
}

Related

Save PDF file to a user-defined default directory in iCloud Drive

I'm asking this question because I did not find any answer, and I'm starting to believe that it's not possible, due to security reasons. But who knows?
In my app, I simply let the user save a PDF file using UIActivityViewController. The user then chooses Save to file, then selects iCloud Drive.
Now, users ask me to be able to select a default location once and for all.
Is it possible? This location would of course be outside the app container, then I suppose iOS won't grant access unless the user selected it itself.
Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.
See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController

How to store data localy in swift osx app?

I'm working on my first osx App and I want to save arrays of objects that I've created on a "project file" like you do in any program when using the "save" button.
I have been looking different ways to do it, Core Data, Document based app, but, I'm not sure how it works any of them to choose the best option for my app.
I want to save arrays of objects that have inside more arrays and other strings and doubles that contain information of the app that the user added. ( It can be a lot of data ) So for that reason I think Userdefault is not a good idea.
I also want to make the app able to open one of this projects saved.
So, could you help me to find which is the best way to do it?
I can suggest you to read iOS FileSystem Overview.
You must use the Data container to locate your local files. For this, you have to locate the NSDocumentDirectory with the NSUserDomainMask (call to NSSearchPathForDirectoriesInDomains) and use standard NSFileManager class.

Where to store SQLite file from app user

In my project I have stored my sqlite(DB file) file in Document directory and also set UIFilesharingMode - NO , but now user can able to acces the file using Xcode->orginizor and also he can able to modify in table and able to change the data in that dable .
My requirement is, how I can hide or restrict user to not access that file.
If any one have any intelligent idea please share me.
Thanks.
You have to use encryption. There's no way to prevent someone accessing Documents folder and there's nowhere for you to store the sqlite file.

How to retrieve the data from the database using CoreData

I am learning core data concept and i want to use this in my simple app.
I have did the sample from the below link.
http://www.techotopia.com/index.php/An_iOS_4_iPhone_Core_Data_Tutorial_%28Xcode_4%29
i have did everything and followed the steps described in that link.
Generally i have added the data to tables(entity) and fetched the records using core data.
But my question is==> Once i closed(killed) the app from simulator (or) device means, the data stored in db also cleared. Next time when open that app again means, db will be empty.
In the above link also, this would be happened.
How to store data permanently in db(sqlite) using core data?
i want data(records) which i stored previous in that db. How to achieve it?
Please Help in this regards!!!
Thanks in advance.
Tutorial from raywenderlich would be a good start to learn for coredata... below is the link for the same...
http://www.raywenderlich.com/934/core-data-tutorial-getting-started
For your question : i want data(records) which i stored previous in that db. How to achieve it?
if you will delete the app either from device or simulator your database will be deleted. If you are testing on simulator and you have made db file in Resource bundle then everytime you run the project, Your database will be replaced by your database file in Project bundle..
please see clear yourself how project refers to db while running in simulator.

Does data base change with new update iPhone app

I have a program that my user save something on it. I want to release new version.
My question is: if my users update their app, will their data still be there or not?
My new release its not part of database.
When you update an app, the data is preserved. As far as I am aware, the process is the same as when you test a new build from Xcode.
The only time this could be an issue is if you are using CoreData, and you update your model. In this case, the old store will not work with your new model unless you migrate the old store. Apple has documentation on migrating CoreData stores here.
The database will be in sandbox of the app. So until user deleted the app the database will be there. You can upgrade the app. But if there is something changes into database then you again need to copy the new database to documents directory either by installing the app again and remove the older version Or by manage through code.
All contents of the Documents directory on device is preserved, update only replaces the application bundle, which is read-only anyway.
Can you please let us know for saving what kind of data model you are using, whether Core Data stack or SQLite. If you are using one of them, its pretty obvious you have to write and fetch your DB from documents directory. If your new version does not contain one, it wont work either.