My app involves a user being able to drag specific items such as volume sliders and UIImage views. My goal is to be able to save the locations of the items so that the user can not have to drag the items again after re-launch. Unfortunately, I have seen errors along taking the ‘saving CGRect rect = item.frame to NSuserDefaultsorNSKeyedArchiver‘ route. Any other suggestions?
My app involves a user being able to drag specific items such as volume
Share
If you’re using keyed archiving on iPhone, UIKit specifically supports an addition that looks like this:
-encodeCGRect:forKey:and does precisely what you want. See the Apple docs for NSCoder’s UIKit additions.If you’re using NSUserDefaults, you don’t get the luxury of using an explicit encoder for CGRects, but as some other answers say, you could save them as strings using
NSStringFromCGRect()and its reverse.