我对 iOS 和 Objective-c 很陌生。我正在尝试pList
在我的应用程序中自动生成一个看起来像这样的。
到目前为止,Value => Key
如果我将 for 循环替换为
for (NSString* exercisePictureName in bigPictureData) {
[data setObject:exercisePictureName forKey:exercisePictureName];
}
但我的问题是我不知道如何在循环结束时构造逻辑以创建如图所示的文件结构。因为它必须是准确的。
任何人都可以为我指出如何构建我的循环的正确方向,以便它创建具有正确格式的文件????
- (void) createImageListFromSource {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"exercisePictures.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"exercisePictures.plist"] ];
}
//To insert the data into the plist
NSArray* bicepPictureData = [self getAllimagesThatStartWith:@"bicep-"];
NSArray* tricepPictureData = [self getAllimagesThatStartWith:@"tricep-"];
NSArray* absPictureData = [self getAllimagesThatStartWith:@"abs-"];
NSArray* chestPictureData = [self getAllimagesThatStartWith:@"chest-"];
NSArray* backPictureData = [self getAllimagesThatStartWith:@"back-"];
NSArray* bigPictureData = [bicepPictureData arrayByAddingObjectsFromArray:tricepPictureData];
bigPictureData = [bigPictureData arrayByAddingObjectsFromArray:absPictureData];
bigPictureData = [bigPictureData arrayByAddingObjectsFromArray:chestPictureData];
bigPictureData = [bigPictureData arrayByAddingObjectsFromArray:backPictureData];
NSArray* finalData = [[NSArray alloc] init];
for (NSString* exercisePictureName in bigPictureData) {
NSDictionary* data = [[NSDictionary alloc] initWithObjectsAndKeys:exercisePictureName,@"text",exercisePictureName,@"image", nil];
[finalData arrayByAddingObject:data];
NSLog(@"%@",data);
}
NSLog(@"%@",finalData);
[finalData writeToFile: path atomically:YES];
}