Closed biancheng347 closed 5 years ago
??你是说覆盖原来的文件内容??
是的
sir wang | |
---|---|
邮箱:biancheng347@163.com |
Signature is customized by Netease Mail Master
在2019年08月23日 12:19,M了个J 写道:
??你是说覆盖原来的文件内容??
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
let file: string = "......./test.data" let p1 = person() p1.name = "person1" wirte(p1,to: file)
let p2 = person() p2.name = "person2" wirte(p2,to: file)
应该是[p1,p2],但是只有p2
这是合理的
let p1 = Person()
var ps = [p1]
write(ps, to: file)
let p2 = Person() ps.append(p2) write(ps, to: file)
- 或者
```swift
let p1 = Person()
write([p1], to: file)
let p2 = Person()
var ps = read([Person].self, from: file)
ps.append(p2)
write(ps, to: file)
我建议可以提供一个接口 write(addOrUpdate: p2,to: file) ,内部代码是
var ps = read([Person].self, from: file) ps.append(p2) write(ps, to: file)
上层代码不管这些细节
谢谢建议,下个版本考虑下
write_to,会覆盖原来的对象