Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you given any thought at all to the steps involved?</p> <ol> <li>Create a fetch request (possibly with a predicate if you want to filter the results).</li> <li>Execute the fetch request. If successful ...</li> <li>For each instance in the returned results array ...</li> <li>Create a path using the "name" attribute.</li> <li>Write the "message" string to the path you just created.</li> <li>Next instance...</li> </ol> <p>Once you've identified the steps, it's not difficult at all to look up the relevant parts of <a href="http://developer.apple.com/mac/library/navigation/index.html" rel="nofollow noreferrer">the documentation</a> to figure out how to do each step.</p> <p>You could actually perform this in three lines of code if you inline some things and have already verified the target folder is writable and don't care about overwriting.</p> <p><strong>Update</strong></p> <p>Okay, so it takes a minimum of four lines since you can't init a fetch request with an entity description, assuming you ignore fetch errors. Since you asked for the code:</p> <pre><code>NSFetchRequest *fr = [[[NSFetchRequest alloc] init] autorelease]; [fr setEntity:[NSEntityDescription entityForName:@"EntityName" inManagedObjectContext:[self managedObjectContext]]] error:nil]; NSArray *results = [[self managedObjectContext] executeFetchRequest:fr error:nil]; for (id result in results){ [[result valueForKey:@"message"] writeToFile:[basePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.txt", [result valueForKey:@"name"]]] atomically:NO] }; </code></pre> <p>Of course this isn't very readable (ie, it's ugly) and makes all sorts of assumptions, but you get the point. Here's a more complete (and illustratively verbose) way:</p> <pre><code>// Create the fetch request NSFetchRequest * fr = [[[NSFetchRequest alloc] init] autorelease]; [fr setEntity:[NSEntityDescription entityForName:@"EntityName" inManagedObjectContext:[self managedObjectContext]]]; // Execute the fetch request NSError * error = nil; NSArray * results = [[self managedObjectContext] executeFetchRequest:fr error:&amp;error]; if (results) { // Process the results NSString * name; NSString * message; NSString * path; for (id result in results) { // Figure out this result's info name = [result valueForKey:@"name"]; message = [result valueForKey:@"message"]; path = [basePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.txt", name]]; // Write the message to the predetermined path [message writeToFile:path atomically:NO]; } } else { // Error fetching results, so present error to user [NSApp presentError:error]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload