Iterating through the owners object to find the owner details for each car would be highly inefficient, so what is a better approach?
O(n^2)
is perfectly fine for reasonably small n
. On a modern iOS device, you’d have to get into an order of 10k objects for this to even see a performance hit—likely much smaller than what you’re being sent back by JSON.
As others mentioned before in comments, and as the old saying goes, “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil”.
Just code it. If your app is slow, profile it in instruments. Only then can you really know what the bottlenecks in your application are (humans are generally very bad at guessing a priori)
solved Correct way to parse JSON payload with multiple root objects [closed]