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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:48:34+00:00 2026-06-11T15:48:34+00:00

I already take a look around and found the closes answer here: Correct way

  • 0

I already take a look around and found the closes answer here:

Correct way to save/serialize custom objects in iOS

But this is only applicable for custom objects that is user-created. My problem is serializing “SKProduct” which is a derived class that is non-NSCoding compliant. Specifically, the exact error I encountered:

-[SKProduct encodeWithCoder:]: unrecognized selector sent to instance 0x4027160

Does anyone have similar experience?

  • 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-11T15:48:35+00:00Added an answer on June 11, 2026 at 3:48 pm

    I’ll preface this answer by saying there’s probably an easier way; but class substitution during archiving and unarchiving is one approach you could take.

    During archiving, you have the option of setting a delegate that conforms to the NSKeyedArchiverDelegate protocol. All of the methods are optional. The delegate receives a message archiver:willEncodeObject: message during encoding. If you wish to substitute a class during archiving, you can create a substitute object and return it. Otherwise just return the original object.

    In your case, you could create a ‘shadow object’ for SKProduct that encapsulates whatever properties on the original class you are interested in serializing. Then substitute that class during archiving. During unarchiving, you could reverse the process and return SKProduct

    For illustrative purposes, here’s an example. Mind you, I’ve left out the reverse substitution part – but if you read the docs on NSKeyedUnarchiverDelegate I think it would be clear.

    #import <Foundation/Foundation.h>
    
    @interface NoncompliantClass:NSObject
    @property (nonatomic,assign) NSInteger foo;
    @end
    
    @implementation NoncompliantClass
    @synthesize foo = _foo;
    @end
    
    @interface CompliantClass:NSObject <NSCoding>
    @property (nonatomic,assign) NSInteger foo;
    @end
    
    @implementation CompliantClass
    @synthesize foo = _foo;
    
    - (void)encodeWithCoder:(NSCoder *)coder {
        [coder encodeInteger:self.foo forKey:@"FooKey"];
    }
    
    - (id)initWithCoder:(NSCoder *)coder {
        self = [super init];
        if( !self ) { return nil; }
    
        _foo = [coder decodeIntegerForKey:@"FooKey"];
        return self;
    }
    
    @end
    
    @interface ArchiverDelegate:NSObject <NSKeyedArchiverDelegate>
    @end
    
    @implementation ArchiverDelegate
    - (id)archiver:(NSKeyedArchiver *)archiver willEncodeObject:(id)object {
        NSString *objClassName = NSStringFromClass([object class]);
        NSLog(@"Encoding %@",objClassName);
        if( [object isMemberOfClass:[NoncompliantClass class]] ) {
            NSLog(@"Substituting");
            CompliantClass *replacementObj = [CompliantClass new];
            replacementObj.foo = [object foo];
            return replacementObj;
        }
        return object;
    }
    @end
    
    int main(int argc, char *argv[]) {
        @autoreleasepool {
            NoncompliantClass *cat1 = [NoncompliantClass new];
            NoncompliantClass *cat2 = [NoncompliantClass new];
            NSArray *herdableCats = [NSArray arrayWithObjects:cat1,cat2,nil];
    
            ArchiverDelegate *delegate = [ArchiverDelegate new];
            NSMutableData *data = [NSMutableData data];
            NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
            [archiver setDelegate:delegate];
            [archiver encodeObject:herdableCats forKey:@"badKitties"];
            [archiver finishEncoding];
        }
    }
    

    This logs:

    2012-09-18 05:24:02.091 TestSerialization[10808:303] Encoding __NSArrayI
    2012-09-18 05:24:02.093 TestSerialization[10808:303] Encoding NoncompliantClass
    2012-09-18 05:24:02.093 TestSerialization[10808:303] Substituting
    2012-09-18 05:24:02.094 TestSerialization[10808:303] Encoding NoncompliantClass
    2012-09-18 05:24:02.094 TestSerialization[10808:303] Substituting
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to take text like below (if it was already in
Take a look at the following progression of images: What's happening here is first
I have read some threads regarding this and I did already take steps to
What I would like to take ownership of a hid device that may already
Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
I want to be able to take an image that i have already captured
If there is already a discussion about this somewhere, I'll take a link as
Already found this page with some helpful hints. Problem is I need to debug
I need to create a custom, reusable view component. I've been trying to look
Take a look at: http://jsfiddle.net/PPsHd/ As expected, hovering over the center div triggers 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.