如何在本地保存SKProduct对象? [英] How to save SKProduct object locally?

查看:987
本文介绍了如何在本地保存SKProduct对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试保存SKProduct对象,并将其与类NSKeyedArchiver一起存档,但会生成 - [SKProduct encodeWithCoder:]:无法识别的选择器发送到实例的错误。

I have tried to save a SKProduct object with archiving it with the class NSKeyedArchiver but it generates an error as -[SKProduct encodeWithCoder:]: unrecognized selector sent to instance.

+ (void)saveProduct:(SKProduct *)product
{
     NSData *data = [NSKeyedArchiver archivedDataWithRootObject:product];
    [[NSUserDefaults standardUserDefaults] setValue:data forKey:PRODUCT];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

有没有办法保存SKProduct的实例?

Is there a way to save an instance of SKProduct or not?

推荐答案

您的SKProduct类需要符合NSCoding协议。

Your SKProduct class needs to conform to the NSCoding protocol.

换句话说,您需要在SKProduct类中填写这两个方法。

In other words you need to fill out these two methods in your SKProduct class.


  • (void)encodeWithCoder:(NSCoder *)aCoder;

  • (id)initWithCoder:(NSCoder *)aDecoder;

这将带你的SKProduct类,并将其分解,以便它可以序列化和反序列化。

This will take your SKProduct class and break it down so that it can be serialized and unserialized.

这篇关于如何在本地保存SKProduct对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆