免费电子公章印章在线制作,萧山区seo关键词排名,网站开发是什么经营范围,如何做框架网站为什么80%的码农都做不了架构师#xff1f; 很多时候我们都需要将对象序列化#xff0c;比如将一个对象存入到NSUserDefault 里面去的时候#xff0c;由于NSUserDefault支持存入的类型有限制#xff0c;所以很多时候我们需要将NSObject类型的对象转换成NSDa… 为什么80%的码农都做不了架构师 很多时候我们都需要将对象序列化比如将一个对象存入到NSUserDefault 里面去的时候由于NSUserDefault支持存入的类型有限制所以很多时候我们需要将NSObject类型的对象转换成NSData再存入进去。 - (id)initWithCoder:(NSCoder *)aDecoder
{self [super init];if (self) {self.country [aDecoder decodeObjectForKey:country];self.city [aDecoder decodeObjectForKey:city];self.region [aDecoder decodeObjectForKey:region];self.street [aDecoder decodeObjectForKey:street];self.location [aDecoder decodeObjectForKey:location];}return self;
}- (void)encodeWithCoder:(NSCoder *)aCoder
{[aCoder encodeObject:_country forKey:country];[aCoder encodeObject:_city forKey:city];[aCoder encodeObject:_region forKey:region];[aCoder encodeObject:_street forKey:street];[aCoder encodeObject:_location forKey:location];
} 当你要进行对象拷贝的时候需要遵循NSCopy协议 - (id)copyWithZone:(NSZone *)zone {id copy [[[self class] alloc] init];if (copy) {[copy setId:[self.id copyWithZone:zone]];[copy setNickName:[self.nickName copyWithZone:zone]];}return copy;
} 转载于:https://my.oschina.net/megan/blog/181463