cocoa - Archiving and Unarchiving results in Bad Access -


I am having trouble setting up a model object in which to maintain the user's visual status in the simple graphics application Sealier can be made in the iPhone

I am trying to pass those properties to the model objects and to save the background color and the frame of all the existing layers on the screen which implements the NSCoding protocol and then in an NMTTABEER, the owner of the App Rep Then I store the array with NSKeyedArchiver and store it in NSUserDefaults.

Each collector's background collector's property is converted to UIColor so that it can be encoded for collection by model object. I feel that I am inadvertently unselecting the array or not reorganizing the position correctly with an unstable array when I try to use the UIColor object stored in the model object, then give me an EXC_BAD_ACCESS get.

I thought that this is probably a bug with UISCLOR object encoding, so dragging values ​​with CGColorGetComponents function from CGColorRef and trying to encode and archive them into the array, but I'm bad The same results were found after the inconsistency, so I think I am just doing it wrong.

This is my model object:

  @ interface aliards: NSObject & lt; Nscding & gt; {UIColor * color; Cgfr frame; } @ Property (retaining) UIColor * color; @protect (assign) CGR frame; @end @implementationEilayerData @ synthesis color; @ Synthesis frame; - (zero) encoded codec: (encoder *) encoder; {[Codec encoded object: Color: @ "color"]; [Coder encodeCGRect: for frame: @ "frame"]; } - (id) initWithCoder: (NSCoder *) coder; {Self = [[Alliedada Elok] Init]; If (self! = Zero) {color = [encode decodeObjectForKey: @ "color"]; Frame = [encode decodeCGRectForKey: @ "frame"]; } Healthy return; } @end  

And this is my archive implementation:

  @implementation AppDelegate - (zero) applicationInternet: (UIApplication *) application {NSArray * layersArray = ViewController.view.layer.sublayers; Data array = [nsmutbaar array array]; For (aliiers * layers in layers) aliardata * layer data = [[alliedada alok] init]; LayerData.frame = layer.frame; UIColor * layerColor = [UIColor colorWithCGColor: layer.backgroundColor]; LayerData.color = layerColor; [Datairaid object: layer data]; [Layer release release]; } [[NSUserDefaults Standard User Defaults] Set Object: [NSKEdAirArchor archivesDateAuthObject: LayerDataArray] for: @ "Savirer"]; } And here is the situation where I restore the state:  
  @implementation ViewController - (zero) viewDidload {{Super ViewDoadload} ; SpaceView = [[AISpaceView alloc] initWithFrame: [[UIScreen main screen] border]]; Self.view = spaceView; [Space scene release]; SpaceView.delegate = self; NSUserDefaults * currentDefaults = [NSUserDefaults Standard User Default]; NSDT * submit data report more = [current defaults objectForkey: @ "saved yes"]; If (DataProperty saved! = ZERO) {[Self-Reserved Data: Presenting DataSquarer Data]; }} - (Zero) Restored StateWithData: (NSData *) data {NSArray * savedLayers = [NSKeyedUnarchiver unarchiveObjectWithData: data]; If (saved layers! = Zero) {NSArray * restoredLayers = [[NSArray alloc] initWithArray: saved layer]; (For layerDataObject in AILayerData * restoredLayers) {UIColor * layerColor = layerDataObject.color; Alleyier * Nouler = [[Allar Elock] Init]; NewLayer.backgroundColor = layerColor.CGColor; NewLayer.frame = layerDataObject.frame; NewLayer.is = selected; [Self.view.layer addSublayer: newLayer]; [New layer release]; } [Restored Layer Release]; [Space scene Layer Layout Charger]; }} @end  

Any help with this is greatly appreciated. I am very much a noob, I was converting encoding, collection and NSRRA's NSARRA into a very similar way by changing the float of color and getting poor access.

You definitely want to retain color in the initWithCoder:

  Color = [[coder decodeObjectForKey: @ "color"] retained];  

Or, the dot syntax as the color was declared as property

  self. Color = [encode decodeObjectForKey: @ "color"];  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -