que je fais:NSKeyedUnarchiver: iPhone .v. Simulator
NSString *current_path = [[NSBundle mainBundle] bundlePath];
NSString *string_path = [NSString stringWithFormat:
@"%@/filedstring", current_path];
my_string_ = [[NSKeyedUnarchiver unarchiveObjectWithFile:string_path] retain];
La chaîne archivée est le texte d'un UITextField
que nous UnArchive ici. J'ai essayé avec et sans current_path
.
Tout cela fonctionne très bien lors de l'exécution dans le simulateur (membre de la classe NSString *my_string_
est non nul), mais lorsqu'il est exécuté sur mon iPhone my_string_
est nul.
Pourquoi est-ce?
Merci pour les réponses rapides tous.
Ajoutant à la réponse de Jason Coco, archive et décompressez ici:
NSString *library_path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
NSString *username_path = [library_path
stringByAppendingPathComponent:@"Caches/filedstring"];
Astuce: lorsque vous générez des chemins à l'aide de 'NSString', utilisez la méthode' stringByAppendingPathComponent: '. Voir: http://bit.ly/fRKJZL –
"Objective-C, iPhone, NSKeyedUnarchiver" n'est pas un titre très descriptif. – vikingosegundo
@vikingosegundo: Pouvez-vous recommander un titre qui serait plus descriptif s'il vous plaît? @ShaggyFrog: Oui, bien sûr. – SK9