【发布时间】:2017-07-22 00:20:46
【问题描述】:
我正在使用下面的代码在应用程序中创建一个 nsdictionary。
NSDictionary *allImportDict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:containerId], @"containerId",
[NSNumber numberWithInt:docTypeId], @"docTypeId",filextension, @"fileExt",metaDataFiellds, @"metaDataFields",[NSNumber numberWithInt:tmpRepoId], @"repositoryId",[NSNumber numberWithInt:1], @"pagesCount",
tmpSessionID, @"sessionId", fileName, @"title",guid, @"tmpFileName",[NSNumber numberWithInt:tmpUserID], @"userId",
nil];
但它创建字典如下
allImportDict 的打印说明:
{
containerId = 2;
docTypeId = 1;
}
请指导我为什么它不包括所有键,因为大多数键都丢失了?
【问题讨论】:
-
检查你的
filextension, @"fileExt" -
这有什么问题?
-
filextension好像是nil,然后停止构造字典。 -
如果使用短语法:=@{@"containerId":[NSNumber numberWithInt:containerId],andSo On},会崩溃。但是对于
initWithObjectsAndKeys:,它将在第一个 nil 值处停止。 “这就是为什么”你自己把nil放在最后。 -
@iOSGuy - 如果您有疑问,请添加静态数据并检查
标签: ios objective-c xcode dictionary nsdictionary