Xcode 8 - changes to where Core Data/Sqlite Database are saved? - xcode

Xcode has always saved the Core Data/Sqlite database files of any given App in that App's Documents folder - by default. But has that just gotten changed in Xcode 8?
I just created a new Core Data App (in Xcode 8.1) and after running the App I couldn't find the usual three sqlite files in the app's Documents folder. Instead, and after much digging around, I discovered those sqlite files in the App's Application Support folder, which is located inside that app's Library folder.
Is this a bug? Or is this the new thing now?
I thought that if we wanted to persist data in an iOS App, the data had to be written into the Documents folder - and that calling saveContext() did just that, automatically.
Anyone know what's going on?

Related

Replace core data model whilst in development without migrating the data (OSX xcode 8.1 on El Capitan)

I'm quite new to OSX and xCode development so any help here appreciated. I'm developing an OSX app that stores data in core data and I want to clear the core data model so that it gets re-generated without having to do a migration as I've not pushed the app to any devices yet. I'm incrementally playing around and adding entities as well as changing attributes/etc on existing entities.
I get this error when running the app via xcode after I've added an attribute to an already created entity:
The managed object model version used to open the persistent store is
incompatible with the one that was used to create the persistent
store.
I've looked at these questions and answers and I'm not getting them to work:
Deleting CoreData store on OS X?
How do I overcome XCode object model version error?
The answer that seems most likely to resolve this (which doesn't work for me) is to go to ~/Library/Developer/Xcode/DerivedData and delete the application folder there. The DerivedData folder does hold a folder with the name of my application and it does get re-generated when I delete it and have the project open in xCode. In fact I've removed all folders in that DerivedData folder but still the same issue.
Anyone knows how to solve this on OSX xcode 8.1 running El Capitan? My App's deployment target is macOS 10.11.
Assuming this is not a document-based app, the Core Data persistent store file will be located in ~/Library/Containers/[your bundle ID]/Data/Documents/. You can remove the full container or specific files. For a document-based app, of course, it'd be in the document.
On iOS you'd just delete the app, but on OS X it's a little different.
Based on comments etc, I'm sharing two ways I've found that solves this issue for me.
Option 1 - adding app sandbox capability.
Add the capability of 'app sandbox' to your app. The data store then gets moved to the ~/Library/Containers/<appName>. When you want to regenerate the core data store to get around versioning issues, you can then delete that folder.
Option 2 - find out the core data persistent store location via code and then delete those files.
As per Tom Harrington: My app used an NSPersistentStoreCoordinator as U could see in my AppDelegate's core data setup. I got the urls of the persistent stores via this in the AppDelegate.swift (I added this just before where the crash happens when the core data versioning error occurs):
for store in (coordinator?.persistentStores)!
print("store url: \(store.url)")
}
This showed that the location of the persistent story for my app was ~/Library/Application Support/com.apple.toolsQA.CocoaApp_CD/TableViewPlayGround.st‌​oredata. FYI: My app bundle id is co.uk.gamba.TableViewPlayGround so this means the data store is not kept in folders relating to my app's bundle when running via xcode. The core data model got replaced without error each time I deleted that file and restarted the app in xcode.

Recover xcode project from installed app on iPhone

I exedentaly deleted my xCode project, but I still have app installed on my iPhone. Is it somehow possible to retrieve at least some part of original project files from app itself?
No, it's not possible to do this.
You may be able to recover the original archive file created prior to installation on your device from inside the following directory (depending on how you deleted the original project) which may be of help.
~/Library/Developer/Xcode/Archives/

Why does XCTest save a ton of data to my /private/vars/folders/rx/ folder?

I'm using XCtest with XCode 6.3 to test an app of mine. I've noticed that it seems to be saving a ton of data to my /private/vars/folders/rx/ folder. If I delete my app's Derived Data these XCTest folders don't get deleted, and if I restart my computer it's still there too. Is this data safe to delete or do I need it?
I used DaisyDisk (awesome program by the way!) to take a look at my computer's memory and I see this:
So I thought I'd take a look at what was in each of these folders. When I looked, it seemed like XCTest was the culprit.
When running my tests I include a large bundle of jpgs that is around 1.7 GB. I'm working on streamlining my app testing so that I don't need the large bundle, but I'm still curious if I can safely delete some of these older folders.
Yes, they are safe to delete. This is where Xcode stores built copies of your applications when built in "Unit Test" mode. Just as Xcode has a Derived Data folder for building OS X apps, it has another location for storing XCTest data (storing this data in the Derived Data folder wouldn't be appropriate, since that is used to store built copies of the application intended to be run by the user).
You should note, though, that Xcode will probably put the data back there again the next time you try to run your app's unit tests, and it may take longer to build/run since some of the cached data is gone. It's up to you whether the trade-off is worth it.
And by the way, Xcode builds your entire project to run XCTest, because your tests might depend on certain resources being there in your app bundle. So that's why the folder is so large.

sandboxing an existing OSX app

I have an existing OSX app that supports OSX 10.5 onwards. I want to publish it to the AppStore and therefore I need to sandbox the app. I guess sandbox app should be supporing 10.7 onwards.
The app uses a folder in the username directory to create temp files etc
It also copies a sql db file which already has empty tables to the same temp folder and upates records as the app is used.
Furthermore if there is a crash it picks up logs from the crashlog folder of osx and requests user to submit them to developer.
Question
with a sanbox app, where do I store temp files ?
Where should I place the db file which can be read/witten to + new App update should be able to find exsting db file.
Should the custom code for crash reporter be kept or be made redundant ?
Thanks
where do I store temp files ?
In the directory recommended by NSTemporaryDirectory(). (This applies to both sandboxed and non-sandboxed applications.)
Where should I place the db file which can be read/witten to
In your application's Application Support directory. Use NSSearchPathForDirectoriesInDomains() to find it, then append your application's name. Again, this is the same whether you're sandboxed or not.
new App update should be able to find exsting db file.
Not possible. You can ask the user to locate the existing file with a NSOpenPanel, but you can't open it yourself, because it'd be outside your sandbox.
Should the custom code for crash reporter be kept or be made redundant ?
You'll need to remove it, because it won't work under sandboxing — crash reports are not stored to your sandbox. You will receive crash reports for your application through iTunes Connect.
Alternatively, you may want to look into a third-party crash reporting service like PLCrashReporter.
There is a mechanism to migrate the data of an existing App into the sandbox: Migrating an App to a Sandbox on developer.apple.com
This is done once the newly sandboxed app is launched the first time. If you can determine where the database was stored, you can migrate it into the sandbox.

Bundled content in an app store app

I am trying to get my app submitted to the mac app store and I am having a bit of a design problem. Our app is an authoring tool and comes bundled with many projects created with the tool. Before the time of the app store, we would ship our app as an .img file which contianed a project directory and our app. Since I am only going to be submitting the .app file to the app store
with my app I am wondering where I should but the projects directory.
Initially I tried to put the projects directory inside of the bundle but this will not work because it is possible for the user to make changes to projects which might add new files to the project directory and this would make the sandboxing unhappy and mark the app as invalid.
What is the correct place to store such resources? I assume they should go inside the container? If so, what would be an elagent way to deploy this projects directory? Since we do not have installers in Apple land what would be the best place to deploy this projects directory? Do I just need to check on app launch if the projects are present and if not copy them from the bundle? This seems wrong.
Do I just need to check on app launch of the projects are present and if not copy them from the bundle?
Actually, this sounds right to me. As you said, the user cannot change/add any files in the app bundle. If you have resources there that the user needs to interact with, I would copy them to the ~/Library/Application Support/MyApp/ folder when they are needed. The user can then interact with the files from that location. (When sandboxed they go into a different but related location.)
I don't really know what your app does, but it would also seem like a possibly useful feature to "reset" the project files/folders back to a starting state. So copying the files in this way would allow for that kind of behavior as well.

Resources