来自 NSArray 的 NSDictionary 丢失了一些值

NSDictionary from NSArray lose some values

我必须修复一个开发的应用程序,该应用程序使用 NSDictionary 在选择特定值时显示数据。但问题是这个字典没有显示我传递给它的所有数据。

在我的情况下,每个 NSArray:

有 296 个值
NSArray *departments = [aPerson.stringDepartment componentsSeparatedByString:@"--"];  // has 296 el.
NSArray *blocks = [aPerson.stringBlocks componentsSeparatedByString:@"--"];  // has 296 el.

我知道每个 NSArray 都有 296 个值,因为我调试了这个应用程序并在 Xcode Assistant Editor

中看到了它的值

然后这是让我发疯的简单行:

self.depend = [NSDictionary dictionaryWithObjects:departments forKeys:blocks];  // has 291 el.

这只是 return 291 个值

如何确保每个值都在我的 NSDictionary 中创建一个新的 key/value?

看起来 blocks 数组有重复项。 NSDictionary 是一个 hash table,因此它不能包含具有相同键的两个不同值。