Я пытаюсь создать файл plist, записать в него данные, а затем прочитать данные из него, используя приведенный ниже код, но приложение каким-то образом вылетает. Я пытаюсь сохранить строковое значение. Кто-нибудь может помочь мне с этим,
//PLIST FILE START..
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
//And write data:
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//here add elements to data file and write data to file
//NSString *value = rowValue;
[data setObject:[NSString stringWithFormat:@"%@", rowValue] forKey:@"value"];
[data writeToFile: path atomically:YES];
[data release];
//Read Data..
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock example int value
NSString *test;
test = [savedStock objectForKey:@"value"];
[savedStock release];
NSLog(@"PLIST VALUE:%@",test);
//PLIST FILE END..
Ошибка, которую я получаю,
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4b25af0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dd9be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2e5c2 objc_exception_throw + 47
2 CoreFoundation 0x00ddb6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d4b366 ___forwarding___ + 966
4 CoreFoundation 0x00d4af22 _CF_forwarding_prep_0 + 50
5 Gavel Edge 0x00003e1e -[JobViewController tableView:didSelectRowAtIndexPath:] + 832
6 UIKit 0x00358794 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
7 UIKit 0x0034ed50 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
8 Foundation 0x000617f6 __NSFireDelayedPerform + 441
9 CoreFoundation 0x00dbafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
10 CoreFoundation 0x00dbc594 __CFRunLoopDoTimer + 1220
11 CoreFoundation 0x00d18cc9 __CFRunLoopRun + 1817
12 CoreFoundation 0x00d18240 CFRunLoopRunSpecific + 208
13 CoreFoundation 0x00d18161 CFRunLoopRunInMode + 97
14 GraphicsServices 0x0170e268 GSEventRunModal + 217
15 GraphicsServices 0x0170e32d GSEventRun + 115
16 UIKit 0x002f142e UIApplicationMain + 1160
17 Gavel Edge 0x00001de4 main + 102
18 Gavel Edge 0x00001d75 start + 53
19 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'