gpt4 book ai didi

ios - writeToFile 不适用于 NSDictionary

转载 作者:可可西里 更新时间:2023-11-01 05:00:54 25 4
gpt4 key购买 nike

<分区>

我环顾了其他类似的问题,但没有任何效果。

我设法在我的 Plist 上只写了字典的一对(对象/键)(例如:setObject:itemProperties[0] forKey[0])。但我想添加所有对象和键。到目前为止我没有管理(返回错误)。有帮助吗?

 // Path to Documents Folder

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"items.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path])
{
path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"items.plist"] ];
}

NSMutableDictionary *items;

if ([fileManager fileExistsAtPath: path])
{
items = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
}
else
{
// If the file doesn’t exist, create an empty dictionary
items = [[NSMutableDictionary alloc] initWithCapacity:5];
}

// array of the item properties
NSArray *itemProperties = @[myItem.itemTitle, myItem.itemImage, myItem.itemPositionX, myItem.itemPositionY, myItem.itemHeight, myItem.itemWidth];

// Set the key values for each field
NSArray *keys = @[@"Title", @"Image", @"PositionX", @"PositionY", @"Height", @"Width"];


[items setObject:itemProperties forKey:keys];

//Save dictionnary to Plist
[items writeToFile: path atomically:YES];

if (![items writeToFile:path atomically:YES]) {
NSLog(@"Error with creating Plist");
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com