gpt4 book ai didi

iphone - 如何创建一个 NSDictionarys 数组

转载 作者:行者123 更新时间:2023-12-01 17:43:32 25 4
gpt4 key购买 nike

我想获取我存储到我的核心数据对象之一的信息,并将这些数据存储到 NSArrayNSDictionary对象,以便我可以将此数组发送到我的一个 View 并在表格 View 中显示数据。

但是我不太确定如何获得 NSDictionary进入NSArray ,这是我的获取请求,希望有人可以帮我把 NSDictionary变成 NSArray ..我不确定如何执行此操作,因为我如何循环通过核心数据对象。

// Test listing all FailedBankInfos from the store
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Manuf" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSError *error;

NSMutableDictionary *tempManufacturerDictionary = [[ NSMutableDictionary alloc] init];

NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (Manuf *manuf in fetchedObjects) {
[tempManufacturerDictionary setObject:manuf.hasMod forKey:@"HASMOD"];
[tempManufacturerDictionary setObject:manuf.isLocked forKey:@"ISLOCKED"];
[tempManufacturerDictionary setObject:manuf.isReg forKey:@"ISREG"];
[tempManufacturerDictionary setObject:manuf.main forKey:@"MAIN"];

// How do I put the Dictionary above into an array?
}

任何帮助,将不胜感激。

最佳答案

您可以实例化 NSMutableArray在进入循环之前,并声明一个新的NSMutableDictionary在每次迭代中,像这样:

    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
NSMutableArray *array = [NSMutableArray array];
for (Manuf *manuf in fetchedObjects) {
NSMutableDictionary *tempManufacturerDictionary = [NSMutableDictionary dictionary];
[tempManufacturerDictionary setObject:manuf.hasMod forKey:@"HASMOD"];
[tempManufacturerDictionary setObject:manuf.isLocked forKey:@"ISLOCKED"];
[tempManufacturerDictionary setObject:manuf.isReg forKey:@"ISREG"];
[tempManufacturerDictionary setObject:manuf.main forKey:@"MAIN"];

[array addObject:tempManufacturerDictionary];
}

您也可以设置 resultType您的提取请求为 NSDictionaryResultType并首先从获取请求中获取字典数组。

关于iphone - 如何创建一个 NSDictionarys 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12631259/

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