Core data testing: force external storage on iOS
I am trying to test core data's External Storage
. Is there a way to force core data to write the data to a file? Adding a large data/image does not seem to work.
https://stackoverflow.com/a/7926505/429763
func setupOnDiskTestStore() {
let mom = NSManagedObjectModel.mergedModel(from: [Bundle.main, Bundle(for: type(of: self))])
psc = NSPersistentStoreCoordinator(managedObjectModel: mom!)
let store = try! psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: storeURL(),
options: nil)
expect(store).notTo(beNil())
moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
moc.persistentStoreCoordinator = psc
}
ios core-data
add a comment |
I am trying to test core data's External Storage
. Is there a way to force core data to write the data to a file? Adding a large data/image does not seem to work.
https://stackoverflow.com/a/7926505/429763
func setupOnDiskTestStore() {
let mom = NSManagedObjectModel.mergedModel(from: [Bundle.main, Bundle(for: type(of: self))])
psc = NSPersistentStoreCoordinator(managedObjectModel: mom!)
let store = try! psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: storeURL(),
options: nil)
expect(store).notTo(beNil())
moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
moc.persistentStoreCoordinator = psc
}
ios core-data
add a comment |
I am trying to test core data's External Storage
. Is there a way to force core data to write the data to a file? Adding a large data/image does not seem to work.
https://stackoverflow.com/a/7926505/429763
func setupOnDiskTestStore() {
let mom = NSManagedObjectModel.mergedModel(from: [Bundle.main, Bundle(for: type(of: self))])
psc = NSPersistentStoreCoordinator(managedObjectModel: mom!)
let store = try! psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: storeURL(),
options: nil)
expect(store).notTo(beNil())
moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
moc.persistentStoreCoordinator = psc
}
ios core-data
I am trying to test core data's External Storage
. Is there a way to force core data to write the data to a file? Adding a large data/image does not seem to work.
https://stackoverflow.com/a/7926505/429763
func setupOnDiskTestStore() {
let mom = NSManagedObjectModel.mergedModel(from: [Bundle.main, Bundle(for: type(of: self))])
psc = NSPersistentStoreCoordinator(managedObjectModel: mom!)
let store = try! psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: storeURL(),
options: nil)
expect(store).notTo(beNil())
moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
moc.persistentStoreCoordinator = psc
}
ios core-data
ios core-data
edited Nov 20 '18 at 19:49
Zsolt
asked Nov 20 '18 at 13:31
ZsoltZsolt
2,12732443
2,12732443
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
There's no way to force it to use external storage. The checkbox says it's allowed, but there's no way to make it required. As noted in the page you link to, it's related to the size of the data, so larger data blobs will be stored externally.
For testing only-- you can inspect the contents of the external storage directory to see what's there. This is completely undocumented, so you can't rely on it in an app, but it might be useful for testing. The data goes in a hidden directory in the same directory as your persistent store file. For example if your persistent store is named MyData.sqlite
and it's located in the application support directory (which is where NSPersistentContainer
puts it, unless you tell it to use a different location), then the external storage (if any) will be in Application Support/.MyData_SUPPORT/_EXTERNAL_DATA/
. There will be one file per externally stored data object.
You can't match the files to managed objects by name, because the file names are UUIDs and the UUIDs aren't available in code. But if you were to create a single new managed object with external storage enabled, and you then found that there was a single new file in that directory, you'd know that the new file corresponds to the new object.
thanks Tom. I set things up in testing withNSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..
– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394133%2fcore-data-testing-force-external-storage-on-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's no way to force it to use external storage. The checkbox says it's allowed, but there's no way to make it required. As noted in the page you link to, it's related to the size of the data, so larger data blobs will be stored externally.
For testing only-- you can inspect the contents of the external storage directory to see what's there. This is completely undocumented, so you can't rely on it in an app, but it might be useful for testing. The data goes in a hidden directory in the same directory as your persistent store file. For example if your persistent store is named MyData.sqlite
and it's located in the application support directory (which is where NSPersistentContainer
puts it, unless you tell it to use a different location), then the external storage (if any) will be in Application Support/.MyData_SUPPORT/_EXTERNAL_DATA/
. There will be one file per externally stored data object.
You can't match the files to managed objects by name, because the file names are UUIDs and the UUIDs aren't available in code. But if you were to create a single new managed object with external storage enabled, and you then found that there was a single new file in that directory, you'd know that the new file corresponds to the new object.
thanks Tom. I set things up in testing withNSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..
– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
|
show 1 more comment
There's no way to force it to use external storage. The checkbox says it's allowed, but there's no way to make it required. As noted in the page you link to, it's related to the size of the data, so larger data blobs will be stored externally.
For testing only-- you can inspect the contents of the external storage directory to see what's there. This is completely undocumented, so you can't rely on it in an app, but it might be useful for testing. The data goes in a hidden directory in the same directory as your persistent store file. For example if your persistent store is named MyData.sqlite
and it's located in the application support directory (which is where NSPersistentContainer
puts it, unless you tell it to use a different location), then the external storage (if any) will be in Application Support/.MyData_SUPPORT/_EXTERNAL_DATA/
. There will be one file per externally stored data object.
You can't match the files to managed objects by name, because the file names are UUIDs and the UUIDs aren't available in code. But if you were to create a single new managed object with external storage enabled, and you then found that there was a single new file in that directory, you'd know that the new file corresponds to the new object.
thanks Tom. I set things up in testing withNSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..
– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
|
show 1 more comment
There's no way to force it to use external storage. The checkbox says it's allowed, but there's no way to make it required. As noted in the page you link to, it's related to the size of the data, so larger data blobs will be stored externally.
For testing only-- you can inspect the contents of the external storage directory to see what's there. This is completely undocumented, so you can't rely on it in an app, but it might be useful for testing. The data goes in a hidden directory in the same directory as your persistent store file. For example if your persistent store is named MyData.sqlite
and it's located in the application support directory (which is where NSPersistentContainer
puts it, unless you tell it to use a different location), then the external storage (if any) will be in Application Support/.MyData_SUPPORT/_EXTERNAL_DATA/
. There will be one file per externally stored data object.
You can't match the files to managed objects by name, because the file names are UUIDs and the UUIDs aren't available in code. But if you were to create a single new managed object with external storage enabled, and you then found that there was a single new file in that directory, you'd know that the new file corresponds to the new object.
There's no way to force it to use external storage. The checkbox says it's allowed, but there's no way to make it required. As noted in the page you link to, it's related to the size of the data, so larger data blobs will be stored externally.
For testing only-- you can inspect the contents of the external storage directory to see what's there. This is completely undocumented, so you can't rely on it in an app, but it might be useful for testing. The data goes in a hidden directory in the same directory as your persistent store file. For example if your persistent store is named MyData.sqlite
and it's located in the application support directory (which is where NSPersistentContainer
puts it, unless you tell it to use a different location), then the external storage (if any) will be in Application Support/.MyData_SUPPORT/_EXTERNAL_DATA/
. There will be one file per externally stored data object.
You can't match the files to managed objects by name, because the file names are UUIDs and the UUIDs aren't available in code. But if you were to create a single new managed object with external storage enabled, and you then found that there was a single new file in that directory, you'd know that the new file corresponds to the new object.
answered Nov 20 '18 at 16:45
Tom HarringtonTom Harrington
52.9k5103131
52.9k5103131
thanks Tom. I set things up in testing withNSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..
– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
|
show 1 more comment
thanks Tom. I set things up in testing withNSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..
– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
thanks Tom. I set things up in testing with
NSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..– Zsolt
Nov 20 '18 at 17:59
thanks Tom. I set things up in testing with
NSSQLiteStoreType
and I am using a 10MB image.. I presume that would "force" core data to move the data to a file, but it does not seem to be the case..– Zsolt
Nov 20 '18 at 17:59
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I don’t know what the limit is. It may change in different versions of iOS. In a quick test I was using a 250MB file.
– Tom Harrington
Nov 20 '18 at 19:16
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
I must be missing something. I ended up using a 300MB image and still no luck. I updated my question with the method I use for setup.
– Zsolt
Nov 20 '18 at 19:49
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
Nothing you can do in code affects whether external storage is used, unless you’re creating the model in code rather than with the model editor.
– Tom Harrington
Nov 20 '18 at 19:53
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
It's also not impossible that there's more to it than just size, because the process is entirely undocumented.
– Tom Harrington
Nov 20 '18 at 21:25
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394133%2fcore-data-testing-force-external-storage-on-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown