utahiosmac / Marshal

Marshaling the typeless wild west of [String: Any]
MIT License
697 stars 62 forks source link

Progress to user when parsing many records? #111

Open davros1970 opened 7 years ago

davros1970 commented 7 years ago

I could use a suggestion on how to best provide progress when parsing a JSON array of a zillion records. Been using the frameworks simple syntax to unmarshal the array with my object implementing Unmarshaling protocol. Works perfectly fine, but when I have many records, how can I provide a 'percent complete' back to the user?

` // This one liner blasts thru the millions of elements in my JSON array to unmarshal, // but doesn't let me know which index its on so I can give the user progress feedback.

let records: [MyRecord] = try? jsonObject.value(for: "BillonsOfRecords") `

jarsen commented 7 years ago

That's a good question. As designed, I don't believe there's a good way for any of the existing API to expose and index. I'm not sure of a good way to handle this short of writing your own version of one of the existing functions that takes a closure which can accept an index and is called on each pass of the mapping.

bwhiteley commented 7 years ago

I wonder if you could do something with UnmarshalingWithContext.