ARC forbids explicit message send of 'retain' issue

僤鯓⒐⒋嵵緔 提交于 2019-11-27 19:31:16
MrHappyAsthma

You are currently using the ARC to reference count for you. (ARC is "Automatic Reference Counting", a new feature to iOS 5). Therefore you do not need to manually retain or release. You can either remove your retain calls all together or turn off ARC by doing the following:

Click on the name of the project on the navigation view in the left side, go to Targets -> Build Phases and add -fno-objc-arc to the "compiler flags" for any relevant files.

See here for info on removing.

See here for basic info on ARC.

Anny

I solved the problem as below. The code is for Objective-C.

  1. Whichever file you wrote a method for getting images from CIImage to CGImageRef:

    CGImageRef cgImage = [_ciContext createCGImage:currentImage fromRect:[currentImage extent]];
    

    make that file as non ARC. Go to Project -> BuildPhase -> ComplieSources -> Your File -> add "-fno-objc-arc" to your file.

  2. If you have .pch file in your project, make the following line comment:

    #if !__has_feature(objc_arc)
    #error This file must be compiled with ARC.
    #endif
    
  3. Go to the method which is used for creating images using the following function:

    CGImageRef cgImage = [_ciContext createCGImage:currentImage fromRect:[currentImage extent]];
    

    Declare _ciContext like this:

    1. In the .h file, declare:

      @property (strong, nonatomic)   CIContext* ciContext;
      
    2. In your method, create the context:

      EAGLContext *myEAGLContext = [[EAGLContext alloc]
              initWithAPI:kEAGLRenderingAPIOpenGLES2];
      _ciContext = [CIContext contextWithEAGLContext:myEAGLContext      options:nil];
      
    3. Use the _ciContext for creating images.

    4. Write the following method in the same file:

       -(void)dealloc
       {
          [super dealloc];
          [EAGLContext setCurrentContext:nil];
       }
      

Turning ARC on or off is a project level setting, if you need to have code that works in both modes you need to use

#if __has_feature(objc_arc)
//dont do a release or a retain or autorelease
#else
//do the release
#endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!