Fetching all data from an Entity and printing only displays the last record

前端 未结 2 1799
时光说笑
时光说笑 2021-01-29 14:57

I\'m trying to fetch all of the data from a particular Core Data Entity and place each record into a string. However the following code only prints the LAST record that it acce

2条回答
  •  自闭症患者
    2021-01-29 15:30

    If you are trying to concatenate all of the formattedData strings into a single NSString printedData, that's not what your code is doing, right? In each iteration over your managed objects, you are re-assigning printedData. That's why you only get the last record.

    I'm inferring that you want printed data to accumulate all of the formattedData strings derived from your NSManagedObject instances. If that's the case, then you need to declare printedData as an NSMutableString and append formattedData strings to that mutable string in each iteration over your managed objects, e.g.

    for( NSManagedObject *info in fetchedObjects )
    {
        formattedData = [NSString stringWithFormat://blah blah blah
        [printedData appendString:formattedData];
    }
    

提交回复
热议问题