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 6571597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:54:10+00:00 2026-05-25T14:54:10+00:00

I have a lot of binary data on Core Data which I would like

  • 0

I have a lot of binary data on Core Data which I would like to remove and save as files so I setup the code so that it would run a manual migration.

The problem is that because I have to pull binary from Core Data and save them to files, the migration process could take a very long time depending on how much data there is.

I would like to show a simple progress label so that users wouldn’t think that the app is frozen.

// app did launch
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    // add the progress label
    self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(103, 36, 114, 21)];
    [self.progressLabel setText:@"0%"];
    [self.window addSubview:self.progressLabel];
    [self.window makeKeyAndVisible];
    ...
    // start migration
    [self progressivelyMigrateURL:storeURL];
    ...
}

// manually migrate store
- (BOOL)progressivelyMigrateURL:(NSURL*)sourceStoreURL
{
    NSLog(@"start progressivelyMigrateURL");
    ...
    // create the migration manager
    NSMigrationManager *manager = [[NSMigrationManager alloc] initWithSourceModel:sourceModel destinationModel:targetModel];
    ...
    // register for KVO of migration progress here
    [manager addObserver:self forKeyPath:@"migrationProgress" options:NSKeyValueObservingOptionNew context:NULL];

    // start the migration
    if (![manager migrateStoreFromURL:sourceStoreURL type:type options:nil withMappingModel:mappingModel toDestinationURL:destinationStoreURL destinationType:type destinationOptions:nil error:&error])
    {
        return NO;
    }
    ...
}

// handle KVO of migration process here
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqual:@"migrationProgress"])
    {
        float migrationProgress = [[change objectForKey:NSKeyValueChangeNewKey] floatValue];
        int percent = migrationProgress * 100;
        [self.progressLabel setText:[NSString stringWithFormat:@"%d%", percent]];
        [self.progressLabel layoutIfNeeded];
        [self.progressLabel setNeedsDisplay];

        NSLog(@"migrationProgress: %d", percent);
        NSLog(@"self.testLabel text: %@", self.testLabel.text);
    }
}

The migration runs perfectly and I can confirm that the NSLog is returning incrementing values while the migration is taking place.

The problem is that self.progressLabel does not redraw every time the progress is updated and just skips from 0% to 100% while the migration is taking place. I know I can’t run the migration on a separate thread. How can I make this work?

  • 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-05-25T14:54:10+00:00Added an answer on May 25, 2026 at 2:54 pm

    You precisely need to perform the migration on a background thread, and update the UI as you get progress notifications on the main thread.

    - (void)startMigration {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSMigrationManager  * manager = [[NSMigrationManager alloc] initWithSourceModel:sourceModel destinationModel:destinationModel];
        [manager addObserver:self forKeyPath:@"migrationProgress" options:0 context:NULL];
        BOOL success = [manager migrateStoreFromURL:sourceStoreURL type:type options:nil withMappingModel:mappingModel toDestinationURL:destinationStoreURL destinationType:type destinationOptions:nil error:&error];
        [manager removeObserver:self forKeyPath:@"migrationProgress"];
        if(success) {
            dispatch_async(dispatch_get_main_queue(), ^{
            // Go back to the main thread and continue…
            });
        }
    }
    

    And when getting notifications:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        dispatch_sync(dispatch_get_main_queue(), ^{
            CGFloat progress = [(NSMigrationManager *)object migrationProgress];
            // Update UI progress indicator
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection containing a LOT of Data Transfer Objects that I need
We have lot of code like: IPerson { Eat(); } Persion : IPerson {
I save data using binary serialization. Now I have changed a field in the
I have a lot of constants that are somehow related, at some point I
We have a lot of unit tests but they aren't run every night. I
I have a LINQ query mapped with the Entity Framework that looks something like
This is the situation: We have some binary files (PDFs, PPTs, ZIPz, etc.) stored
I've been loading a lot of binary files recently using C/C++, and I'm bothered
I have a WebView that I want to save as a WebArchive. I just
How can I extract information from a binary file that I don't have the

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.