0
- (void)drawRect:(CGRect)rect {

}

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CGContextRef context = UIGraphicsGetCurrentContext();

    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];

    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);

    CGContextMoveToPoint(context, point.x, point.y);
    CGContextAddLineToPoint(context, point.x + 100, point.y);

    CGContextStrokePath(context);
}

And it gives me error

[Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextAddLineToPoint: invalid context 0x0. If you want to see the backtrace, please se CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Serj Semenov
  • 267
  • 4
  • 11
  • There is no current context in `touchesBegan`. Is this a custom `UIView` subclass? Please provide some more details about what you are trying to do (update your question, don't post comments). – rmaddy Jun 06 '18 at 18:23
  • Well ur comment helped) and yes it was in UIView subclass... tnx a lot – Serj Semenov Jun 06 '18 at 18:38

0 Answers0