danielctull-tests / State-Restoration-Test

Simple example of state restoration and my expectations
0 stars 0 forks source link

Close #1

Open sgoodwin opened 10 years ago

sgoodwin commented 10 years ago

I feel like you're missing some of the details they go over in the 2 videos from 2012 and 2013.

Overall I don't see what's wrong with needing to re-fetch the managed objects you're depending on for your detail views though I don't think you're supposed to be trying to encode your contexts.

danielctull commented 10 years ago

I've no problem with storing the URIRepresentation for the managed object, it's really the only way to store a reference to it.

My single issue with state restoration is with how to deal with objects that are shared among multiple view controllers, and how to propagate them through the view controller stack on decoding.

Some advice a while back on the devforms was to encode the context. Which would likely work if state restoration worked the same as regular NSCoding, which doesn't appear to be the case.

sgoodwin commented 10 years ago

Sounds like more of a problem with your application architecture than with the State Restoration stuff. I mean, it doesn't do everything for you, but that's to be expected since there's no way anyone but you can know how your Core Data stack is setup.

PeteC commented 10 years ago

It's common practice to pass an object to a view controller for it to display - a sound application architecture. For Core Data based apps, these would commonly be NSManagedObjects or a subclass.

State restoration requires you to store details of the object, which we can do by storing the URI representation of it's ID. If you weren't using Core Data, this could be the unique ID of the object. During restoration, you can easily decode the ID back from the coder, but then you need to fetch the actual object from your store (whether it be an NSManagedObjectContext or another type of object store).

This is the problem I and many others have tried to solve with the help of numerous Apple engineers (not just those in the dev forums). I don't agree that it is a problem with app architecture and not a problem with the state restoration API. Encoding and decoding the MOC comes close but the MOCs you get back will be different for each view controller.