У меня в приложении есть словарь с вложенными словарями (согласно «флеш-картам»).По какой-то причине NSDictionary не будет записывать в файл.Если я просто вызываю writeToFile в своем словаре, это не работает, и NSPropertyListSerialization возвращает список свойств, недопустимый для формата.Код выглядит следующим образом:
#import "flashCard.h"
#define kFront @"front"
#define kBack @"back"
@implementation flashCard
- (id) init
{
if (self = [super init])
{
cards = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc] initWithObjectsAndKeys:
@"aetas/aetatis", kFront,
@"lifetime, age, generation", kBack,
nil], [NSNumber numberWithInt: 1],
[[NSDictionary alloc] initWithObjectsAndKeys:
@"amicitia/amicitiae", kFront,
@"alliance, friendship", kBack,
nil], [NSNumber numberWithInt: 2],
[[NSDictionary alloc] initWithObjectsAndKeys:
@"amicus/amici", kFront,
@"friend", kBack,
nil], [NSNumber numberWithInt: 3],
[[NSDictionary alloc] initWithObjectsAndKeys:
@"animus/animi", kFront,
@"mind, heart, spirit, courage", kBack,
nil], [NSNumber numberWithInt: 4],
nil];
currentSide = [[NSString alloc] init];
currentCard = 1;
currentSide = kFront;
}
return self;
}
позже, в той же реализации ...
- (void) saveSet
{
NSLog(@"saveSet called");
NSSavePanel *cocaoSavePanel = [NSSavePanel savePanel];
int buttonPressed = [cocaoSavePanel runModal];
if (buttonPressed != NSOKButton)
{
return;
}
NSLog(@"ok button, with url: %@", [cocaoSavePanel URL]);
NSError *error;
NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:cards
format:NSPropertyListXMLFormat_v1_0
options: 0
error: &error];
if (plistData)
{
[plistData writeToURL:[cocaoSavePanel URL] atomically:YES];
NSLog(@"File Saved Successfully");
}
else {
NSLog(@"%@", error);
}
}
Любая помощь будет принята.
РЕДАКТИРОВАТЬ: после пересмотра:
2011-08-12 13:00:47.937 flashcards[14452:a0f] saveSet called
2011-08-12 13:00:48.763 flashcards[14452:a0f] ok button, with url: file://localhost/Users/sam/Desktop/asdf
2011-08-12 13:00:48.764 flashcards[14452:a0f] {
3 = {
back = friend;
front = "amicus/amici";
};
2 = {
back = "alliance, friendship";
front = "amicitia/amicitiae";
};
1 = {
back = "lifetime, age, generation";
front = "aetas/aetatis";
};
4 = {
back = "mind, heart, spirit, courage";
front = "animus/animi";
};
}
2011-08-12 13:00:48.764 flashcards[14452:a0f] Property list invalid for format: 100
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all