Pergunta

I am doing the following to store an object as an archive:

[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:self.shapeLayers] forKey:@"mySavedArray"];

I know it works fine as I'm able to reload it. Question is, how can I find this file? I'd like to see its size after its archived to compare the archive to the .m file, and also eventually I might need to upload it to a server. Am I saving it correctly, or should I go about that a different way?

Foi útil?

Solução

The standard user defaults is stored in a single file in "App Home Directory/Library/Prefereneces/". The archived data is part of that file. It is not saved as a separate file. If you want to get the data size, use .length property of NSData.

NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.shapeLayers];
NSUInteger size = [archivedData length];
[[NSUserDefaults standardUserDefaults] setObject: forKey:@"mySavedArray"];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top