ios24-数据持久化-对象归档(3)
//
// Created by on 13-6-18.
// Copyright 2013年 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
//要实现当前类对象,就必须实现nscoding协议
@interface Student : NSObject<NSCoding>
{
NSString *studentId;
NSString *studentName;
NSString *studentClass;
}
@property (nonatomic,retain) NSString *studentId;
@property (nonatomic,retain) NSString *studentName;
@property (nonatomic,retain) NSString *studentClass;
@end
------------------------------
//
// Student.m
// ios24-saveObjectToFile
//
// Created by on 13-6-18.
// Copyright 2013年 __MyCompanyName__. All rights reserved.
//
#import "Student.h"
@implementation Student
@synthesize studentId,studentName,studentClass;
//进行归档编码
-(void)encodeWithCoder:(NSCoder *)aCoder{
//将属性
[aCoder encodeObject:studentId forKey:@"studentId"];
[aCoder encodeObject:studentName forKey:@"studentName"];
[aCoder encodeObject:studentClass forKey:@"studentClass"];
}
//对对象进行读取读取出来
-(id)initWithCoder:(NSCoder *)aDecoder{
//进行属性解码
self.studentId=[aDecoder decodeObjectForKey:@"studentId"];
self.studentName=[aDecoder decodeObjectForKey:@"studentName"];
self.studentClass=[aDecoder decodeObjectForKey:@"studentClass"];
return self;
}
@end
相关新闻>>
- 发表评论
-
- 最新评论 更多>>