标准反序列化
//
标准反序列化
如果有自定义的类,应该在类中实现NSCoding协议,NSCopying是可选的吧,放在这儿写copy时可以参考下
//
//
//
//
//
//
//
#import <Foundation/Foundation.h>
#define kClass
#define kSubClass
#define kName
#define kPrice
#define kSelected
@interface item_info : NSObject
<
NSCoding,
NSCopying
>
{
}
@property (nonatomic, copy) NSString *strClass;
@property (nonatomic, copy) NSString *strSubClass;
@property (nonatomic, copy) NSString *strName;
@property (nonatomic, copy) NSString *strPrice;
@property (nonatomic, assign) BOOL bSelected;
@end
//
//
//
//
//
//
//
#import "item_info.h"
@implementation item_info
@synthesize strClass = _strClass;
@synthesize strSubClass = _strSubClass;
@synthesize strName = _strName;
@synthesize strPrice = _strPrice;
@synthesize bSelected = _bSelected;
- (void)dealloc
{
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
}
- (id)copyWithZone:(NSZone *)zone
{
}
@end
使用实例:
序列化:
// KeyedArchiver
反序列化:
另附数据源构造核心代码,虽然结果可能设计不太合理,希望大家提出宝贵意见:
- (void)initDataSource
{
//
}
kShoppingListFileName:
<?xml version="1.0" encoding="UTF-8"?>
<shoping>
<class name="图书" >
<subclass name="计算机">
<item name="《C#入门》"price="
<item name="《ios入门》"price="24.00"/>
<item name="《架构设计》"price="33.00"/>
<item name="《敏捷实战》"price="55.00"/>
<item name="《ASP.net从入门到精通》"price="56.00"/>
</subclass>
<subclass name="外语">
<item name="《商务口语》"price="9.00"/>
<item name="《朗讯辞典》"price="99.00"/>
<item name="《1天1句》"price="8.0"/>
<item name="《我爱背单词》"price="7.6"/>
<item name="《看图说话》"price="7.0"/>
</subclass>
<subclass name="教材">
<item name="《大学语文》"price="32.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="小说">
<item name="《美人》"price="37.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="励志">
<item name="《学会说NO》"price="98.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="动漫">
<item name="HAHAH"price="3.0"/>
<item name="《??》"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
</class>
<class name="家具">
<subclass name="床">
<item name="HAHAH"price="3.0"/>
<item name="国王大床"price="39898.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="桌">
<item name="小圆桌"price="98.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="椅">
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="太师椅"price="32.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="灯具">
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="熊猫台灯"price="983.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="门窗">
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="玻璃门"price="983.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="地板">
<item name="HAHAH"price="3.0"/>
<item name="楠木地板"price="9333333.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
</class>
<class name="电子设备">
<subclass name="电脑">
<item name="HAHAH"price="3.0"/>
<item name="DELL"price="3000.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="手机">
<item name="HAHAH"price="3.0"/>
<item name="iphone"price="3000.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="摄影摄像">
<item name="HAHAH"price="3.0"/>
<item name="DELL"price="3000.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
<subclass name="打印扫描">
<item name="HAHAH"price="3.0"/>
<item name="HP"price="3000.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
<item name="HAHAH"price="3.0"/>
</subclass>
</class>
</shoping>