gpt4 book ai didi

ios - __weak self 没有按预期工作

转载 作者:行者123 更新时间:2023-11-29 01:34:51 24 4
gpt4 key购买 nike

我有以下代码:

    __weak id weakSelf = self;
[geocoder reverseGeocodeLocation:currLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if(error)
NSLog(@"Geocoder failed with error: %@", error);
else
weakSelf.placeMark = [placemarks objectAtIndex:0];



}];
NSLog(@"current placemark: %@", self.placeMark);

}

我想使用 weak self 的原因是因为我在另一个例子中看到了这一点,当时我正在研究为什么“Xcode 无法通过 self.some_property 在此 block 中找到”我的属性。无论如何,我现在收到错误消息,placeMark 不是 weakSelf 的成员。 placeMark 被声明为强的非原子属性。任何帮助表示赞赏

最佳答案

尝试强制转换您的变量,因为这里您只有一个 (id),所以 Xcode 无法识别您实例的自定义属性

__weak typeof(self) weakSelf = self;

关于ios - __weak self 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33080627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com