kakaopensource / KakaJSON

Fast conversion between JSON and model in Swift.
MIT License
1.16k stars 124 forks source link

write_to,会覆盖原来的对象 #14

Closed biancheng347 closed 5 years ago

biancheng347 commented 5 years ago

write_to,会覆盖原来的对象

CoderMJLee commented 5 years ago

??你是说覆盖原来的文件内容??

biancheng347 commented 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.

biancheng347 commented 5 years ago

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

coderflower commented 5 years ago

这是合理的

CoderMJLee commented 5 years ago

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)
biancheng347 commented 5 years ago

我建议可以提供一个接口 write(addOrUpdate: p2,to: file) ,内部代码是

var ps = read([Person].self, from: file) ps.append(p2) write(ps, to: file)

上层代码不管这些细节

CoderMJLee commented 5 years ago

谢谢建议,下个版本考虑下