Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
我有一个带有核心数据对象的NSMutableArray。我想创建一个NSString,其中这些对象的格式如下:


  关键字-定义
  
  关键字-定义
  
  关键字-定义


我有以下代码从数组中收集一个索引:

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 - 从带有核心数据的NSMutableArray创建对象的NSString ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19537755/

10-12 15:06