Unrecognized selector sent to instance while archiving data (NSCoding)

前端 未结 5 1900
名媛妹妹
名媛妹妹 2020-12-09 09:48
-(void)transformObjects:(NSMutableArray*)array key:(NSString*)key
{
    NSMutableArray* archiveArray = [[NSMutableArray alloc]initWithCapacity:array.count];

    for         


        
5条回答
  •  既然无缘
    2020-12-09 10:21

    You need to implement NSCoding protocol inside your Furniture object:

    - (void)encodeWithCoder:(NSCoder *)aCoder{
      [aCoder encodeObject:self.yourpoperty forKey:@"PROPERTY_KEY"];
    }
    
    -(id)initWithCoder:(NSCoder *)aDecoder{
      if(self = [super init]){
        self.yourpoperty = [aDecoder decodeObjectForKey:@"PROPERTY_KEY"];
      }
      return self;
    }
    

    Basically you specify what should be written (encoded) and read from a file (decoded). Usually for each property you want to store in a file, you make same as I did here in an example.

提交回复
热议问题