【问题标题】:NSDictionary initWithObjectsAndKeys from macro fails宏中的 NSDictionary initWithObjectsAndKeys 失败
【发布时间】:2013-05-29 12:21:20
【问题描述】:

我试图用键和值两个字符串来初始化一个 NSDictionary,我想从一个定义的宏中初始化:

#define _FILETYPES @".c", @"c", @".h", @"c",".cpp", @"cpp", @".d", @"d", @".hs", @"haskell", @".lua", @"lua", @".ml", @"ocaml", @".mli", @"ocaml", @".php", @"php", @".pl", @"perl", @".py", @"python", @".rb", @"ruby", @".scm", @"scheme", @".ss", @"scheme", @".tcl", @"tcl", nil


#define _LANGS @"c", @"C", @"cpp", @"C++", @"d", @"D", @"haskell", @"Haskell", @"lua", @"Lua", @"ocaml", @"OCaml", @"php", @"PHP", @"perl", @"Perl", @"python", @"Python", @"ruby", @"Ruby", @"scheme", @"Scheme", @"tcl", @"Tcl", nil

self.languages = [[NSDictionary alloc] initWithObjectsAndKeys:_LANGS];
self.filetypes = [[NSDictionary alloc] initWithObjectsAndKeys:_FILETYPES];

你能告诉我为什么这不起作用。我之前一直在类似地启动数组... 问题是,一旦到达分配行,代码就会抛出 EXC_BAD_ACCESS

【问题讨论】:

  • 怎么不工作了?
  • 它确实有效 :)
  • 密钥 c 在 _FILETYPES 中被使用了两次

标签: ios macros nsdictionary


【解决方案1】:

你忘记了“.cpp”和“perl”之前的@..

【讨论】:

  • 好收获! - (在问题的代码中,它仅在“.cpp”之前丢失)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多