plist / NSMustableDictionary lesen und schreiben

#pragma mark -
#pragma mark write/read NSDictionary <=> PList

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDirectory = [paths objectAtIndex:0];
    return [docDirectory stringByAppendingPathComponent:@"aktuelleArtikel.plist"];
}

- (NSMutableDictionary *)readFromPlist
{
	NSMutableDictionary* plistDict;
	// File exist ?
	if ([[NSFileManager defaultManager] fileExistsAtPath: [self dataFilePath]]){
		NSString *filePath = [self dataFilePath];
		plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
		//	NSString *value;
		//	value = [plistDict objectForKey:@"ProductVersion"];
	} else {
		plistDict = [[NSMutableDictionary alloc] init];
	}

	return plistDict;
}

- (void)writeToPlist:(NSMutableDictionary *) plistDict
{
    NSString *filePath = [self dataFilePath];
	[plistDict writeToFile:filePath atomically: YES];
}

3 Gedanken zu „plist / NSMustableDictionary lesen und schreiben“

Kommentar verfassen