Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:55:26+00:00 2026-06-04T11:55:26+00:00

Can anyone help me here. I am really stuck. In my code if no

  • 0

Can anyone help me here. I am really stuck.

In my code if no file exists in the Documents location; I create the store, put the data in it and read back from it. This works fine.
However, if a file already exists in that location I am unable to read back from it. I have tried a lot, but am really unsure why it is not working. Some times (very few actually), the very same code will work but the other times it wouldn’t.

Here is the code. When it doesn’t work, the debug message ‘End of useDocument’ in useDocument method is never logged. This is the method where openWithCompletionHandler is called on the UIManagedDocument. The code enters the method but never makes it to the end of that method!

- (void)setupFetchedResultsController
{   NSLog(@"In setupFetchedResultsController");

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"WorkOutTypes"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"workoutName" ascending:YES]];


self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request 
                                                                    managedObjectContext:self.workoutDatabase.managedObjectContext
                                                                      sectionNameKeyPath:nil 
                                                                               cacheName:nil];

NSLog(@"End of setupFetchedResultsController");
}

- (void)pushWorkoutDataIntoDocument:(UIManagedDocument *)document
{   NSLog(@"In pushWorkoutDataIntoDocument");
dispatch_queue_t pushQ = dispatch_queue_create("Push data", NULL);
dispatch_async(pushQ, ^{
    NSArray *workOuts = [NSArray arrayWithObjects:@"Squats", @"Bench Press", @"Overhead Press", @"Bent Over Rows", nil];
    [document.managedObjectContext performBlock:^{
        for (NSString *workout in workOuts) {
            [WorkOutTypes workoutName:workout inManagedObjectContext:document.managedObjectContext];
        }
    }];        
});
dispatch_release(pushQ);
}

- (void)useDocument
{   NSLog(@"In useDocument");
NSLog(@"File path - %@", [self.workoutDatabase.fileURL path]);
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.workoutDatabase.fileURL path]]) {
    NSLog(@"1");
    [self.workoutDatabase saveToURL:self.workoutDatabase.fileURL 
                 forSaveOperation:UIDocumentSaveForCreating 
                completionHandler:^(BOOL success){
                    [self setupFetchedResultsController];
                    [self pushWorkoutDataIntoDocument:self.workoutDatabase];
                }];
}
else 
    if (self.workoutDatabase.documentState == UIDocumentStateClosed) {
        NSLog(@"2");
        [self.workoutDatabase openWithCompletionHandler:^(BOOL success){
            NSLog(@"handler called");[self setupFetchedResultsController];}];
    }
    else
        if (self.workoutDatabase.documentState == UIDocumentStateNormal) {
            NSLog(@"3");
            [self setupFetchedResultsController];
        }
NSLog(@"End of useDocument");

}

- (void)setWorkoutDatabase:(UIManagedDocument *)workoutDatabase
{   NSLog(@"In setWorkoutDatabase");
if (_workoutDatabase != workoutDatabase) {
    _workoutDatabase = workoutDatabase;
    [self useDocument];
}
}

- (void)viewWillAppear:(BOOL)animated
{   
[super viewWillAppear:animated];
//    self.navigationItem.rightBarButtonItem = self.editButtonItem;

if (!self.workoutDatabase) {
    NSLog(@"Came in");
    NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    url = [url URLByAppendingPathComponent:@"Default Workouts Database"];
    self.workoutDatabase = [[UIManagedDocument alloc] initWithFileURL:url];
    NSLog(@"URL - %@", [url path]);
}
if (self.workoutDatabase) {
    NSLog(@"workoutDatabase created");
}
else
    NSLog(@"workoutDatabase not created");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:55:27+00:00Added an answer on June 4, 2026 at 11:55 am

    Closing the question for now. I reverted to using a traditional Core Data stack instead of a UIManagedDocument. It was quite unreliable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one help me in this error here's the code :- CREATE OR
Can anyone here help me with the integration of the DailyMotion API? I am
Can anyone please help. I'm following a tutorial found here as I have a
can anyone help me.I cant create a new web application.I mean i cant find
Can anyone help. I have an ASP.NET application which has a web.config file so
I'm stuck with recursion, was wondering if anyone can help me out with it.
I am really stuck with an sql query... I hope someone can help shed
iPhone/objC I'm really stuck here and I could use some help, please. Let me
Can anyone help me with this error? alt text http://abbeylegal.com/downloads/parsererror.jpg full image here It
I'm new here and I hope anyonte can help me. I have WCF Service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.