【发布时间】:2023-03-08 14:31:01
【问题描述】:
我写了一个简单的 OC 文件来测试一个__weak 参考
#import "Foundation/Foundation.h"
@interface Foo : NSObject
@property (nonatomic, assign) int a;
- (void)test;
@end
@implementation Foo
- (void)test
{
__weak typeof(self) weakSelf = self;
[weakSelf test];
}
@end
int main()
{
Foo* foo = [[Foo alloc] init];
foo.a = 3;
[foo test];
return 0;
}
使用 clang -rewrite-objc keke.m 编译时出现以下错误:
无法创建 __weak 引用,因为当前部署目标确实 不支持弱引用 __attribute__((objc_ownership(weak))) typeof(self) weakSelf = self;
如何直接在clang 中设置分解目标。我试过了
clang -rewrite-objc -stdlib=libc++ -mmacosx-version-min=10.7 keke.m
但没有运气。
【问题讨论】:
标签: objective-c clang weak-references