不兼容的指针类型将类型为'float [2]'的可保留参数传递给CF函数,期望'const CGFloat*'(又名'const double*')类型

ccg*_*guo 3 xcode ios arm64

我收到这个错误,我在arm64下编译出现了这个错误:

CGContextSetLineDash(line, 0, lengths, 1);  //???
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

- (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;
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*n R 20

在64位体系结构(如arm64)上,CGFloat定义为double8字节浮点数,而float4字节浮点数.因此,您无法将float[]数组传递给期望CGFloat[]数组的函数.

将阵列更改为

CGFloat lengths[] = {4,5};
Run Code Online (Sandbox Code Playgroud)

应该解决问题.