ios开发 - MJExtension

学习链接:

https://www.jianshu.com/p/7e8af12ab5a4

https://www.jianshu.com/p/b4a1956f7578

总结:

  场景:

    假设我想存储  类A  至缓存,并在某时机要读这个数据

  一般用法:

    1、A类 #import <MJExtension/MJExtension.h>

    2、@implementation A

      MJExtensionCodingImplementation

     存储

    3、NSData *data = [NSKeyedArchiver archivedDataWithRootObject:A实例];

    4、[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"key"];

     读取

    5、NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"key"];

            if (data){

                A实例 = [NSKeyedUnarchiver unarchiveObjectWithData:data];

            }

posted @ 2021-12-12 17:03  执||念  阅读(71)  评论(0编辑  收藏  举报