How do I know if my program has ARC enabled or not?

前端 未结 4 656
情歌与酒
情歌与酒 2021-01-31 20:41

I create a project with ARC support using the Xcode project wizard. Compared with a program without ARC support, I did not notice any differences. Is there any hint that can tel

4条回答
  •  天命终不由人
    2021-01-31 21:18

    You can use __has_feature, maybe logging whether the project has ARC in the console like this:

    #if __has_feature(objc_arc)
        // ARC is On
        NSLog(@"ARC on");
    
    #else
        // ARC is Off
        NSLog(@"ARC off");
    
    #endif
    

    Alternatively, instead of just logging whether ARC is on, try making the compiler raise an error if ARC is on (or off) like this:

    #if  ! __has_feature(objc_arc)
        #error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
    #endif
    

提交回复
热议问题