这可能是几个问题捆绑成一个,但这里是情况。我在Objective C中工作,并有一个for循环,这是通过一个字典对象数组...像这样。循环,想要在循环结束时打印出有关字典对象数组的信息
for (NSDictionary *dictionary in array){
log(@"the dictionary object looks like this \n%@\n",dictionary);
log(@"value of someProp in the current dict object is %@",[dictionary valueForKey:@"someProp"]);
}
好吧,这一切都很好,但我想整理它如何打印到控制台一点点。我对客观的C是新手,但在其他语言经验。我想这样做的目标C(写在动作的例子)
var outputString:String;
for (items in dictionary){
outputString += dictionary.toString();
outputString += "value of item in current dict object is " + dictionary [item];// etc
}
// now just print out the contents of outputString;
trace(outputString);
我这里的挑战是整理是字符串类型或的NSString的不是一个对象..
我知道的东西一样
NSString *outputString = @"";
for (//same loop as above in obj-c){
outputString = [outputString stringByAppendingString:**someString**];
}
,但也许我只是用适当的字符串的方法不熟悉的,因为简单地替代字典打印出整部字典对象,其中读取someString将产生一个错误,因为当然一个字典对象不是一个字符串。
所以我想
-accumulate的我想的NSLog出一系列字符串都高达
- 这个总结是什么内容包括在打印出的字典对象的内容(或者也可能是数组对象)将其转换为字符串,并将其添加到outputString。
任何人有任何建议如何去做到这一点?
我认为这是正确的答案,我只是像这样使用它... myString = [NSString stringWithFormat:@“%@%@%@”,a,b,c]; 哪个效果很好。 – djeddiej 2011-02-06 05:45:10