使用宏参数的Objective-C @property

时间:2022-03-08 19:57:40

question:

问题:

I create a class for ARC and No-ARC, but in ARC, use strong, in No-ARC, use retain; So

我创建了一个类为圆弧和无圆弧,但在圆弧,使用强,在无圆弧,使用保留;所以

my code:

我的代码:

    #if __has_feature(objc_arc)
    #define PARAMETER  strong
    #else
    #define PARAMETER  retain
    #endif
    @property (PARAMETER) NSString *myName;

is that right? thanks very much!

是这样吗?非常感谢!

2 个解决方案

#1


6  

I see no reason for doing this. You can use strong in a non-ARC environment too.

我看没有理由这样做。在非弧环境中也可以使用strong。

#2


1  

strong works in ARC and non-ARC, the only thing you have to avoid when ARC is enabled is using autorelease, release and dealloc so this code is unnecessary.

强在ARC和non-ARC中工作,在启用ARC时惟一要避免的事情是使用autorelease、release和dealloc,因此这些代码是不必要的。

#1


6  

I see no reason for doing this. You can use strong in a non-ARC environment too.

我看没有理由这样做。在非弧环境中也可以使用strong。

#2


1  

strong works in ARC and non-ARC, the only thing you have to avoid when ARC is enabled is using autorelease, release and dealloc so this code is unnecessary.

强在ARC和non-ARC中工作,在启用ARC时惟一要避免的事情是使用autorelease、release和dealloc,因此这些代码是不必要的。