#import <Foundation/Foundation.h>
extern void _objc_autoreleasePoolPrint();
int main(int argc, char * argv[]) {
@autoreleasepool {
Person *p = [Person new];
Person __weak *p2 = p;
_objc_autoreleasePoolPrint();
}
}
The result is this:
$ clang -rewrite-objc -fobjc-arc main.m
/var/folders/t0/nty3j9vx1rn8786q_tpclydc0000gn/T/main-2fe2fd.mi:46509:31: error: cannot create __weak reference
because the current deployment target does not support weak references
Person __attribute__((objc_ownership(weak))) *p2 = p;
^
1 error generated.
Please answer
Shouldn’t __Weak be in front of the class name?
weak requires support from the runtime environment.
When you select a suitable minimum version, you can compile the source code with weak modified variables.
The parameter rewrite-objc "exports" objc code into c++ code, and __weak is modified when objc ARC is compiled. Do you want to compile or convert?
To convert, change __weak to __unsafe_unretained.
Remove the rewrite-objc parameter when compiling.