weak

Is it the right way using `[weak self]` in swift closure?

匆匆过客 提交于 2019-12-04 04:18:55
问题 I always using [weak self] in swift closure to prevent reference cycle. Here is the code below, is it the correct way? someTask(completion: {[weak self] (result) in if self == nil { return } //is it safe when reach here? self!.xxx = yyy self!.doLongTermWork() self!.finish() //will crash when self is nil? }) Weak self does not keep a strong hold on the instance. So when self.doLongTermWork() , will self be set to nil again somewhere else? 回答1: Your pattern has race condition. If self was

Cross-Store weak relationship with Fetched Properties?

落爺英雄遲暮 提交于 2019-11-30 07:39:18
I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part of my application). Therefore, I've been looking for a while for a way to code a cross-store relationship using fetched properties. I have not found any example implementations of this. I have a Core Data model using 2 configurations : data model config 1 : UserData (entities relative to user) data model config 2 : ReferenceData (entities relative

Cross-Store weak relationship with Fetched Properties?

北城以北 提交于 2019-11-29 10:16:35
问题 I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part of my application). Therefore, I've been looking for a while for a way to code a cross-store relationship using fetched properties. I have not found any example implementations of this. I have a Core Data model using 2 configurations : data model

What is the proper way to avoid Retain Cycle while using blocks

给你一囗甜甜゛ 提交于 2019-11-27 22:23:01
What is the proper way to add objects in NSMutableArray which is strongly defined by property. [tapBlockView setTapBlock:^(UIImage* image) { [self.myImageArray addObject:image]; // self retain cycle } If I will create weak reference something like __weak NSMutableArray *array = self.myImageArray; [tapBlockView setTapBlock:^(UIImage* image) { [array addObject:image]; // If I will do this then how will I update original Array ? } I have also tried __weak id weakSelf = self; [tapBlockView setTapBlock:^(UIImage* image) { [weakSelf storeImageInaNewMethod:image]; // Calling SToreImageInaNewMethod }

Using as a concrete type conforming to protocol AnyObject is not supported

依然范特西╮ 提交于 2019-11-27 19:00:44
I'm using Swift 2 and using WeakContainer as a way to store a set of weak objects, much like NSHashTable.weakObjectsHashTable() struct WeakContainer<T: AnyObject> { weak var value: T? } public protocol MyDelegate : AnyObject { } Then in my ViewController, I declare public var delegates = [WeakContainer<MyDelegate>] But it is error Using MyDelegate as a concrete type conforming to protocol AnyObject is not supported I see that the error is that WeakContainer has value member declared as weak , so T is expected to be object. But I also declare MyDelegate as AnyObject , too. How to get around

Using as a concrete type conforming to protocol AnyObject is not supported

99封情书 提交于 2019-11-26 22:43:15
问题 I'm using Swift 2 and using WeakContainer as a way to store a set of weak objects, much like NSHashTable.weakObjectsHashTable() struct WeakContainer<T: AnyObject> { weak var value: T? } public protocol MyDelegate : AnyObject { } Then in my ViewController, I declare public var delegates = [WeakContainer<MyDelegate>] But it is error Using MyDelegate as a concrete type conforming to protocol AnyObject is not supported I see that the error is that WeakContainer has value member declared as weak ,

What is the proper way to avoid Retain Cycle while using blocks

∥☆過路亽.° 提交于 2019-11-26 20:58:26
问题 What is the proper way to add objects in NSMutableArray which is strongly defined by property. [tapBlockView setTapBlock:^(UIImage* image) { [self.myImageArray addObject:image]; // self retain cycle } If I will create weak reference something like __weak NSMutableArray *array = self.myImageArray; [tapBlockView setTapBlock:^(UIImage* image) { [array addObject:image]; // If I will do this then how will I update original Array ? } I have also tried __weak id weakSelf = self; [tapBlockView

How to make weak linking work with GCC?

醉酒当歌 提交于 2019-11-26 20:21:14
There seem to be 3 ways of telling GCC to weak link a symbol: __attribute__((weak_import)) __attribute__((weak)) #pragma weak symbol_name None of these work for me: #pragma weak asdf extern void asdf(void) __attribute__((weak_import, weak)); ... { if(asdf != NULL) asdf(); } I always get a link error like this: Undefined symbols: "_asdf", referenced from: _asdf$non_lazy_ptr in ccFA05kN.o ld: symbol(s) not found collect2: ld returned 1 exit status I am using GCC 4.0.1 on OS X 10.5.5. What am I doing wrong? Jeffrey Scofield I just looked into this and thought some others might be interested in my

How to make weak linking work with GCC?

旧时模样 提交于 2019-11-26 06:38:09
问题 There seem to be 3 ways of telling GCC to weak link a symbol: __attribute__((weak_import)) __attribute__((weak)) #pragma weak symbol_name None of these work for me: #pragma weak asdf extern void asdf(void) __attribute__((weak_import, weak)); ... { if(asdf != NULL) asdf(); } I always get a link error like this: Undefined symbols: \"_asdf\", referenced from: _asdf$non_lazy_ptr in ccFA05kN.o ld: symbol(s) not found collect2: ld returned 1 exit status I am using GCC 4.0.1 on OS X 10.5.5. What am