<分区>
要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果。另请参阅:Stack Overflow question checklist
已关闭 9 年前。
<分区>
要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果。另请参阅:Stack Overflow question checklist
已关闭 9 年前。
我有一个NSMutableArray
与核心数据对象。我想创建一个NSString
这些对象的格式如下:
Keyword - Definition
Keyword - Definition
Keyword - Definition
我有以下代码来从数组中收集一个索引:
Term *term = [self.terms objectAtIndex:1];
NSString *string = [NSString stringWithFormat:@"%@ - %@ \r\n", term.keyword, term.definition];
我不太确定如何循环这个,以便数组中的每个索引都被一起添加到字符串中。提前致谢!
最佳答案
NSMutableString *string = [NSMutableString string];
for (Term *term in self.terms)
{
[string appendFormat: @"%@ - %@\r\n", term.keyword, term.definition];
}
//at this point "string" contains keywords and definitions of all terms
关于ios - 使用 Core Data 从 NSMutableArray 创建对象的 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19537755/