多个对象的归档和解归档

OC多个对象的归档和解归档

你说的曾经没有我的故事 提交于 2020-03-01 03:57:58
FJStudent.h #import <Foundation/Foundation.h> @interface FJStudent : NSObject < NSCoding > @property ( nonatomic , copy ) NSString *name; @property ( nonatomic , assign ) int score; @end FJStudent.m #import "FJStudent.h" @implementation FJStudent - ( void )encodeWithCoder:( NSCoder *)aCoder{ [aCoder encodeObject : _name forKey : @"name" ]; [aCoder encodeInt : _score forKey : @"score" ]; } - ( instancetype ) initWithCoder:( NSCoder *)aDecoder{ if ( self = [ super init ]) { _name = [aDecoder decodeObjectForKey : @"name" ]; _score = [aDecoder decodeIntForKey : @"score" ]; } return self ; } - (