AnsweredAssumed Answered

Pushing AGSEnvelope into NSUserDefaults

Question asked by pml on Jun 28, 2012
Latest reply on Jul 3, 2012 by pml
I was trying to push an AGSEnvelope into NSUserDefaults:

         //.h file      @property (nonatomic) IBOutlet AGSMapView *mapView;      @property (nonatomic, strong) AGSEnvelope *mapExtent;     //.m file      NSString *kMapExtent = @"mapExtent";      AGSPolygon *mapExtentPoly = self.mapView.visibleArea;          // see above...self.mapExtent is of type AGSEnvelope     self.mapExtent = mapExtentPoly.envelope;         // this is key to the problem...attempt to convert AGSEnvelope so it can be used as NSData in NSUserDefaults.     self.dataForMapExtent = [NSKeyedArchiver archivedDataWithRootObject:self.mapExtent];    // the program crashes after this line is run       NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];          [defaults setObject:self.dataForMapExtent forKey:kMapExtent];          [defaults synchronize];


This is the error message I get when the program crashes:
[AGSEnvelope encodeWithCoder:]: unrecognized selector sent to instance


I think Apple's classes that inherit from NSCoding can convert themselves to NSData. I see that AGSEnvelope inherits from AGSCoding but it looks to only encode/decode JSON.

Do I need to convert the AGSEnvelope to something like an NSDictionary before putting it into NSUserDefaults? Is this the best solution?

Thanks for any help,
Paul Lohr

Outcomes