Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incompatible pointer types passing retainable parameter of type 'float [2]'to a CF function expecting 'const CGFloat *' (aka 'const double *') type

Tags:

xcode

ios

arm64

I'm getting this error,I compiled under arm64 appear this mistake:

CGContextSetLineDash(line, 0, lengths, 1);  //画虚线

How do I solve this?

- (id)initDashLineWithFrame:(CGRect)frame{
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:frame];

    UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线
    [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状


    float lengths[] = {4,5};
    CGContextRef line = UIGraphicsGetCurrentContext();
    UIColor *coloreline = [UIColor colorWithRed:156/255.0 green:156/255.0 blue:156/255.0 alpha:1];//r(156, 156, 156, 1);
    CGContextSetStrokeColorWithColor(line, coloreline.CGColor);

    CGContextSetLineDash(line, 0, lengths, 1);  //画虚线
    CGContextMoveToPoint(line, 0.0, 5.0);    //开始画线
    CGContextAddLineToPoint(line, 310.0, 5.0);
    CGContextStrokePath(line);

    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();
    return imageView1;
}
like image 612
ccguo Avatar asked Dec 01 '22 01:12

ccguo


1 Answers

On 64-bit architectures (like arm64), CGFloat is defined as double and therefore a 8-byte floating point number, whereas float is a 4-byte floating point number. Therefore you cannot pass a float[] array to a function expecting a CGFloat[] array.

Changing your array to

CGFloat lengths[] = {4,5};

should solve the problem.

like image 199
Martin R Avatar answered Dec 15 '22 17:12

Martin R