gpt4 book ai didi

ios - 保存时 NSArrays 是否保持排序然后从 plist 中检索

转载 作者:行者123 更新时间:2023-11-29 02:40:19 25 4
gpt4 key购买 nike

简单的问题是,当保存到 plist 然后检索时,NSArray 是否保持排序?

当我从 plist 检索数组时遇到排序问题,所以我很好奇。

我觉得也可能是这条线的问题。这些是否保持标题的顺序遵循 titleArr 的顺序?

NSMutableArray *allTitles = [[NSMutableArray alloc] init];
[allTitles addObjectsFromArray:titles];
[allTitles addObjectsFromArray:titleArr];

如何保存到 plist

imageInfo = [[NSMutableArray array] init];

NSMutableArray *Listing = [NSMutableArray array];
[imageInfo addObject:Listing];

NSDictionary *Images = [NSDictionary dictionaryWithObjectsAndKeys:
allTitles, kKeyTitle,
allMediaUrls, kKeyThumbUrl,
allWidths, kKeyThumbWidth,
allHeights, kKeyThumbHeight,
nil];
[Listing addObject:Images];


NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory ,NSUserDomainMask, YES);

NSString *documentsDirectory = [sysPaths objectAtIndex:0];

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"image.plist"];

NSLog(@"Plist File Path: %@", filePath);

BOOL didWriteToFile = [imageInfo writeToFile:filePath atomically:YES];

if (didWriteToFile) {
NSLog(@"Write to .plist file is a SUCCESS!");
} else {
NSLog(@"Write to .plist file is a FAILURE!");
}

最佳答案

是的,如果 titlestitleArr 被排序,那么 allTitles 也会被排序。

首先将添加所有标题对象,然后添加所有对象 titleArr,因为 addObjectsFromArray 方法开始向接收数组的末尾添加对象数组。

更多信息来自 Apple Docs

Adds the objects contained in another given array to the end of the receiving array’s content.

所以是的,plist 将有排序的数组。

关于ios - 保存时 NSArrays 是否保持排序然后从 plist 中检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876983/

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