成员变量retain/assign/copy/strong/assign/unsafe_unretained设置方法

来源:互联网 发布:等式约束优化 数值求解 编辑:程序博客网 时间:2024/06/06 13:07

#ifndef MY_RETAIN

#if __has_feature(objc_arc)

    #define MY_RETAIN strong

#else

    #define MY_RETAIN retain

#endif

#endif


#ifndef MY_ASSIGN

#if __has_feature(objc_arc_weak)

    #define MY_ASSIGN weak

#elif __has_feature(objc_arc)

    #define MY_ASSIGN unsafe_unretained

#else

    #define MY_ASSIGN assign

#endif

#endif


#ifndef MY_COPY

#define MY_COPY copy

#endif



//对象类型使用MY_RETAIN声明

@property (MY_RETAINnonatomicNSURLConnection *connection;

@property (MY_RETAINnonatomicNSMutableDictionary *fieldsToBePosted;

@property (MY_RETAINnonatomicNSMutableArray *filesToBePosted;


//NSString对象类型使用MY_COPY声明

@property (MY_COPYnonatomicNSString *username;

@property (MY_COPYnonatomicNSString *password;


//基本数据类型使用MY_ASSIGN声明

@property (nonatomicMY_ASSIGNNSInteger startPosition;

@property (nonatomicMY_ASSIGNBOOL isCancelled;