saoudrizwan / Disk

Easily persist structs, images, and data on iOS
MIT License
3.1k stars 171 forks source link

Example of Disk working with simple relationships #70

Closed worchyld closed 5 years ago

worchyld commented 5 years ago

I am wondering if there is any examples of using Disk with simple one to many relationships?

saoudrizwan commented 5 years ago

Disk is a wrapper around Codable so you could easily have an array of your 'many' type as long as its Codable.

struct User: Codable {
    let photos: [Photo]
}
struct Photo: Codable {
    let url: String
}
let user = User(photos: [...])
try Disk.save(user, to: .caches, as: "user.json")