如何在NSTextField中显示NSDictonary的内容作为键值对?

时间:2014-07-18 22:29:07

标签: objective-c nsdictionary nstextfield

我想知道如何在NSTextField中完全打印未知大小的NSDictonary的内容?输出应该在最后看起来像这样:

Key1:值
Key2:价值
Key3:价值



KeyN:价值

1 个答案:

答案 0 :(得分:1)

NSMutableString *mutableString = [NSMutableString new];
for (id key in myDictionary)
{
    [string appendFormat:@"%@: %@\n", key, myDictionary[key]];
}
// Delete last newline
[string deleteCharactersInRange:NSMakeRange([string length]-1, 1)];
myTextField.text = mutableString;