Exportieren der Kerndaten in CSV über Mail Composer mit CHCSVParser (von Dave DeLong)

Ich exportiere die Kerndaten mit CHCSVParser (von Dave DeLong) über Mail Composer in csv, aber das Problem ist, dass der Name der Kerndatentabelle anstelle der Zeilenwerte verwendet wird.

Außerdem möchte ich sie in einer bestimmten Reihenfolge, z. B. "Kanalnummer", "Mannloch 1", "Mannloch 2".

Hier ist die Codierung, die ich verwende:

// Abrufen der Daten aus den Kerndaten

NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription
                                          entityForName:@"Input_Details" inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];


request.predicate = [NSPredicate predicateWithFormat:@"rs_Input_project.name = %@", self.projectObject.name];


[request setEntity:entityDescription];
request.resultType = NSDictionaryResultType;

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sewer_No" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];

NSError *error;

NSArray *fetchedObjects = [moc executeFetchRequest:request error:&error];



 //creating a csv CHCSVWriter
NSOutputStream *output = [NSOutputStream outputStreamToMemory];
CHCSVWriter *writer = [[CHCSVWriter alloc] initWithOutputStream:output encoding:NSUTF8StringEncoding delimiter:','];

for (id object in fetchedObjects)
{
    if ([object conformsToProtocol:@protocol(NSFastEnumeration)])
    {
        [writer writeLineOfFields:object];

    }
}

[writer closeStream];


NSData *buffer = [output propertyForKey:NSStreamDataWrittenToMemoryStreamKey];

NSString *string = [[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding];

NSLog(@"Length of Buffer:%d Error:%@",[buffer length],[error localizedDescription]);

if ( [MFMailComposeViewController canSendMail] )
{


    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;

    NSData *myData = [string dataUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"myData csv:%@",myData);
     NSLog(@"string csv:%@",string);

// Fill out the email body text
    NSString *emailBody = @"Sewer_Output";
    [mailComposer setMessageBody:emailBody isHTML:NO];

    //attaching the data and naming it Sewer_Output
    [mailComposer addAttachmentData:myData  mimeType:@"text/cvs" fileName:@"Sewer_Output.csv"];

[self presentModalViewController:mailComposer animated:YES];
}

Antworten auf die Frage(2)

Ihre Antwort auf die Frage