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

  • SEARCH
  • Home
  • 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 6754725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:18:53+00:00 2026-05-26T13:18:53+00:00

I am intending to download and encode an image as shown below. However I

  • 0

I am intending to download and encode an image as shown below.

However I am getting the error -[NSKeyedArchiver encodeObject:forKey:]: archiver has finished; cannot encode anything more’. Can anyone explain why this error occurred and how I can I resolve it?

- (void)encodeWithCoder:(NSCoder *)encoder
{
    dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
        dispatch_async(downloadQueue, ^{
            NSURL *url = [NSURL URLWithString:self.avatar_url];
            NSData *data = [NSData dataWithContentsOfURL:url];
            dispatch_async(dispatch_get_main_queue(), ^{
                self.avatar = [[[UIImage alloc] initWithData:data] autorelease];
                [encoder encodeObject:UIImagePNGRepresentation(self.avatar) forKey:@"avatar"];
            });

        });
}

Error Stack

2011-11-03 00:08:32.645 onethingaday[6897:207] *** Terminating app due to uncaught exception 'NSInvalidArchiveOperationException', reason: '*** -[NSKeyedArchiver encodeObject:forKey:]: archiver has finished; cannot encode anything more'
*** First throw call stack:
(0x29de052 0x26ddd0a 0x2986a78 0x29869e9 0x16e1d40 0x9fdd 0x1d33445 0x1d354f0 0x2915833 0x2914db4 0x2914ccb 0x2d57879 0x2d5793e 0xd89a9b 0x290d 0x2885 0x1)
  • 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-26T13:18:54+00:00Added an answer on May 26, 2026 at 1:18 pm

    You should not use an asynchronous method in -encodeWithCoder:. The reason is simple. The function is usually called like this (in the lower level):

    NSKeyedArchiver* archiver = [NSKeyedArchiver initForWritingWithMutableData:...];
    ...
    [archiver encodeObject:yourObject forKey:@"key"];  // A
    // ^ this calls [yourObject encodeWithCoder:archiver]
    ...
    [archiver finishEncoding];   // B
    

    Your -encodeWithCoder: is asynchronous with GCD. Therefore line A will return before anything happens, and then line B will be executed (still your scheduled function will not be called). This finish the archiver and prevents further encoding on it.

    Later, the asynchronous method is allowed to start, and you download the image and convert it into PNG etc… and finally tell the encoder to -encodeObject:forKey. But this is already too late — the archiver has already been finished long time before! Therefore the exception is thrown.

    To avoid this, you should ensure not to call -encodeObject:forKey asynchronously. The GCD codes should be put outside of the -encodeWithCoder: method, i.e. the image should be completely available before performing the archiving.

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

Sidebar

Related Questions

I am intending to build an iPhone/iPad app that has a feature allowing users
I was intending on use the Title attribute in the @Page directive to customise
I am intending to use SQLite 3 with PHP 5. I found this: http://packages.debian.org/etch/web/php5-sqlite3
I'm intending to create a flash app that pulls images from facebook and displays
I'm intending to use the new .NET 4 Code Contracts feature for future development.
I am still developing this function, but here is what I am intending it
I'm starting to do a small amount of development within my company. I'm intending
I was intending to create a splash screen like the one sported by Visual
This is a loop in a function intending to create elements <li> and give
I'm using a makefile intending to generate dependencies automatically. But with my file, I

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.