I am writing an app which uses CoreData using NSPersistentContainer to save data.
While I am developing the app, I would like to:
examine the data directly
back up the data
see what happens when I change the bundle id
I assume the data is physically stored somewhere, but I’m not sure where to look.
By default NSPersistentContainer stores the database inside app container under directory Libray/Application Support
To locate the full path, in simulator, you can print the applicationSupportDirectory using urls(for:in:) function of the default FileManager:
print(FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first?.path ?? "nil")
If you are running your app on an actual device you can download the application container following this answer.
For sandboxed apps the location goes like this:
~/Library/Containers/…/Data/Library/Application Support/…
Related
I could not find the location in my phone for the data stored when using the App-inventor Companion. Can somebody help me in this?
The "AppInventor>assets" contains the pictures used in the app when using the companion but there is no database. I am using TinyDB.
to delete the assets, delete the directory /AppInventor on your device using a file manager app
to delete TinyDB, use the method TinyDB.ClearAll
I am developing a Today's Extension of an app. I am having some problems regarding App Groups that are used as shared containers between extension and containing app.
Where is the App Group data stored?
How to see what data is stored in the App Group?
Shared Containers is simply a UserDefault dictionary that is shared between Extensions in an App. To store data in the container Init your container using the suiteName UserDefault:
let SharedDefaults = UserDefaults.init(suiteName: "group.com.YOURGROUP")!
TheN to set a value, in this case a String:
SharedDefaults.set("something", forKey: "aKey")
And to retrieve the information (from either the Extension or App) use:
let myString = SharedDefaults.string(forKey: "aKey")
This explains how to to print the contents of the UserDefaults: Easy way to see saved NSUserDefaults?
I am writing a shoebox type application wherein a user enters data into a single window. I’ve configured the data model with Code Data. Apple’s documentation states that user data should be stored in a Library Directory, however the auto-generated code seems to make a directory in the Application Support directory where one, the documentation also states, “should never store user data.” Which is correct?
The other question I have is should I not create an instance of NSPersistentDocument in the applicationDidFinishLaunching method?
User-created data should be managed by the user: the user should decide where they are saved, etc.
Application-created data would indeed belong in the application support directory. If your application creates an NSPersistentDocument without user intervention, this would be the correct place to store it. For example, if you were using NSPersistentDocument to manage application data it would belong in a sandboxed directory such as NSApplicationSupportDirectory.
The File System Programming Guide goes into this in more detail.
My app, Cassius, is happily using an external file (i.e not in ~/Library/Application Support/) to store webView data.
The OSX sandbox is obviously not allowing this. I thus used this GitHub project to ask the user the desired location for the file.
I can create a text file on my desktop using this, successfully going out of the sandbox, but giving a file to my WebView local storage [webPrefs _setLocalStorageDatabasePath:myDirectory]; doesn't work.
In both cases the console report an issue sandboxd: deny file-read-data...
Is there a way for a sandbox'd app to use an external file as a WebView local storage?
Thank you !
Is it possible for extensions access the containing-app's container directory?
For iOS5-based app, i don't want to move all my old data into shared-contatiner, i wish that main-app can remain the same, and the extension just read & write the old data directly, that will be perfect!~
Your widget may never access the containing app's data directly, only if the containing app puts that data into a shared container using app groups. The documentation (including the WWDC videos) is pretty clear about this.
There's a high chance that your iOS-5-based app needs major changes anyway to work nicely on iOS 8.