值转换问题:隐式转换失去整数精度:'NSInteger'(又名'long')到'int32_t'(又名'int')

Dat*_*kar 2 objective-c ios gpuimage xcode5.1

我已将我的Xcode版本从5.0升级到5.1并在GPUImage库GPUImageVideoCamera.m中开始出现错误:301:54:隐式转换失去整数精度:'NSInteger'(又名'long')到'int32_t'(又名'int') )

在这行的下面的函数"connection.videoMaxFrameDuration = CMTimeMake(1,_frameRate);" 发生错误.

- (void)setFrameRate:(NSInteger)frameRate;
{

    _frameRate = frameRate;

    if (_frameRate > 0)
    {

        for (AVCaptureConnection *connection in videoOutput.connections)
        {

            if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])

                connection.videoMinFrameDuration = CMTimeMake(1, _frameRate);

            if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)])

                connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate);

        }
    }

    else

    {
        for (AVCaptureConnection *connection in videoOutput.connections)

        {
            if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])

                connection.videoMinFrameDuration = kCMTimeInvalid; 
                                // This sets videoMinFrameDuration back to default

            if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)])

                connection.videoMaxFrameDuration = kCMTimeInvalid; 
                                // This sets videoMaxFrameDuration back to default

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Man*_*ani 9

问题与此有关architecture.如果您在Xcode 5.1中打开现有项目,它的默认arch设置是64位体系结构.

请参阅Xcode 5.1发行版中的这一行

注意:在Xcode 5.1中打开现有项目时,请注意以下体系结构问题:

  • 构建所有体系结构时,请删除任何显式体系结构设置并使用默认的"标准体系结构"设置.对于之前选择使用"包含64位的标准体系结构"的项目,请切换回"标准体系结构"设置.
  • 当第一次打开现有项目时,Xcode 5.1可能会显示有关使用Xcode 5.0体系结构设置的警告.选择警告提供了修改设置的工作流程.
  • 不能支持64位的项目需要专门将架构构建设置设置为不包括64位.

你可以在这个苹果的文档中看到这一行.

NSInteger在64位代码中更改大小.整个Cocoa Touch都使用NSInteger类型; 它是32位运行时中的32位整数和64位运行时中的64位整数.因此,当从采用NSInteger类型的框架方法接收信息时,请使用NSInteger类型来保存结果.

但是int is a 32-bit integer,只有这样才会出现这个错误.您可以通过将架构设置为standard architecture including 64-bit或执行简单类型转换来解决此问题,如下所示.

connection.videoMinFrameDuration = CMTimeMake((int64_t)1, (int32_t)_frameRate);
Run Code Online (Sandbox Code Playgroud)

请参阅CMTimeMake语法.

CMTime CMTimeMake (
   int64_t value,
   int32_t timescale
);
Run Code Online (Sandbox Code Playgroud)