功能如下:
注意:
|
//从nsobject解析回来
init
(coder aDecoder:
NSCoder
!){
self
.name=aDecoder.decodeObjectForKey(
"Name"
)
as
String
.phone=aDecoder.decodeObjectForKey(
"Phone"
String
}
//编码成object
func
encodeWithCoder(aCoder:
!){
aCoder.encodeObject(name,forKey:
)
aCoder.encodeObject(phone,monospace!important; min-height:inherit!important">)
}
|
具体代码如下:
--- ViewController.swift ---
--- DataModel.swift ---
name:
phone:
String
//构造方法
(name:
=
""
){
.name = name
.phone = phone
()
}
//从nsobject解析回来
!){
as
!
String
String
}
//编码成object
!){
)
}
|