I am working with CgLayers for drawing in iOS, Now I want to store these layers and retrieve it later, so I want to know what are the available options. I tried to use NSMutableDictionary, below is the code,
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGLayerRef testLayer = CGLayerCreateWithContext(UIGraphicsGetCurrentContext(), self.bounds.size, NULL);
CGContextRef context = CGLayerGetContext(testLayer);
CGContextDrawLayerAtPoint(context, CGPointZero, myLayerRef);
// here myLayerRef is my original layer
NSValue *layerCopy = [NSValue valueWithPointer:testLayer];
NSDictionary *lineInfo = [NSDictionary dictionaryWithObjectsAndKeys:layerCopy, @"IMAGE",
nil];
[m_pathArray addObject:lineInfo];
}
-(void) retrieve
{
NSDictionary *lineInfo = [m_pathArray lastObject];
NSValue *val = [lineInfo valueForKey:@"IMAGE"];
CGLayerRef layerRef = (CGLayerRef) [val pointerValue];
CGContextRef context1 = CGLayerGetContext(layerRef);
CGContextDrawLayerAtPoint(context1, CGPointMake(00, 00),layerRef);
[self setNeedsDisplayInRect:self.bounds];
}
Regards Ranjit