automatic-ref-counting

Swift ARC and blocks

风流意气都作罢 提交于 2019-12-19 07:21:34
问题 I'm trying a simple example as seen here: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-XID_88 And this is my code. (Ignore other possible code, this is a empty project with this code written inside an empty UIViewcontroller viewDidLoad) dispatch_async(dispatch_get_main_queue()) { [unowned self] in println(self) } I don't understand why it crashes when I run the

Conditional compilation when using ARC

牧云@^-^@ 提交于 2019-12-19 06:19:19
问题 Is there a way to ask the compiler if ARC is turned on, and then conditionally compile based upon that value? For example, I have a protocol: @protocol ProtocolA @required -(void)protocolMethodOne @optional -(void)protocolMethodTwo; @end If I'm using ARC, I would like to make protocolMethodA optional when using ARC, and required when not using ARC. This is because one of the main reasons for utilizing this method is to dealloc the object instance. With that said, here's what I would like to

how to add ARC in between of project

橙三吉。 提交于 2019-12-19 04:56:43
问题 I am creating iPhone app and in between I need to use SDWebImage. For this I need to use ARC. Any idea how to add ARC in between in project? Note: In one file I have below content. #if !__has_feature(objc_arc) #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag #endif Where should I add -fobjc-arc flag? 回答1: Select Project Form Project Manager | | Targets | | Build Phases | | Compile Sources | | Select File that you Want to crate as ARC. (You can also

Avoiding circular retention using ARC (strong/weak), learning some basics

ε祈祈猫儿з 提交于 2019-12-19 03:42:13
问题 I haven't seemed to run into a problem yet, but I'm trying to make sure I'm using some best practices. Say I have a UITableViewController with a data source of an NSArray of MyObject objects. So in my UITableViewController I declare my data source like: @property (strong, nonatomic) NSArray *dataSource; Then after I touch a cell I want to push a new view that shows a detail view of something, using that cell's MyObject. So in the new UIViewController I have this: @property (strong, nonatomic)

Using unowned inside of a capture list causing a crash even the block itself isn't executed

风格不统一 提交于 2019-12-19 02:15:01
问题 Here, I was playing with leaks, so I've made a strong reference cycle intentionally to see if the Instruments will detect something, and I got unexpected results. The leak shown in Instruments certainly make sense, but the random crash is a bit mysterious (due to two facts I will mention later). What I have here is a class called SomeClass : class SomeClass{ //As you can guess, I will use this shady property to make a strong cycle :) var closure:(()->())? init(){} func method(){} deinit

Understand one edge case of block memory management in objc

六眼飞鱼酱① 提交于 2019-12-18 17:33:45
问题 the code below will crash because of EXC_BAD_ACCESS typedef void(^myBlock)(void); - (void)viewDidLoad { [super viewDidLoad]; NSArray *tmp = [self getBlockArray]; myBlock block = tmp[0]; block(); } - (id)getBlockArray { int val = 10; //crash version return [[NSArray alloc] initWithObjects: ^{NSLog(@"blk0:%d", val);}, ^{NSLog(@"blk1:%d", val);}, nil]; //won't crash version // return @[^{NSLog(@"block0: %d", val);}, ^{NSLog(@"block1: %d", val);}]; } the code runs in iOS 9 with ARC enabled. And I

Understand one edge case of block memory management in objc

好久不见. 提交于 2019-12-18 17:33:06
问题 the code below will crash because of EXC_BAD_ACCESS typedef void(^myBlock)(void); - (void)viewDidLoad { [super viewDidLoad]; NSArray *tmp = [self getBlockArray]; myBlock block = tmp[0]; block(); } - (id)getBlockArray { int val = 10; //crash version return [[NSArray alloc] initWithObjects: ^{NSLog(@"blk0:%d", val);}, ^{NSLog(@"blk1:%d", val);}, nil]; //won't crash version // return @[^{NSLog(@"block0: %d", val);}, ^{NSLog(@"block1: %d", val);}]; } the code runs in iOS 9 with ARC enabled. And I

Compatibility of ARC and Storyboard

岁酱吖の 提交于 2019-12-18 15:49:50
问题 What's the compatibility of ARC and Storyboard considering devices and iOS? Will ARC and Storyboard work on iPhone 3G, 3GS, 4 and 4S? Will ARC and Storyboard work on iOS 4 and 5? 回答1: ARC runs with 5.0 or higher, Storyboard also needs iOS 5. Therefore, both are potentially available with the iPhone 3GS and above. EDIT: Obviously, ARC is also compatible with iOS 4.0 and above, once you don't use weak . I briefly tested it, seems to work. That would mean that the iPhone 3G would also be

Under ARC, are Blocks automatically copied when assigned to an ivar via the property?

假如想象 提交于 2019-12-18 13:17:32
问题 Assume typedef void (^MyResponseHandler) (NSError *error); @property (strong, nonatomic) MyResponseHandler ivarResponseHandler; synthesize ivarResponseHandler = _ivarResponseHandler; - (void)myMethod:(MyResponseHandler)responseHandler { self.ivarResponseHandler = responseHandler; ... } Is the assignment to the ivar through the @property correct? I know that in manual memory management you would have needed self.ivarResponseHandler = [responseHandler copy]; to make sure the block was copied

Does IBOutlet imply __weak?

微笑、不失礼 提交于 2019-12-18 12:01:01
问题 Just starting out with ARC. Pre-ARC, I would just simply declare my outlets as for example: IBOutlet UIButton *button; so I am not retaining it or anything. With ARC, not specifying weak or strong implies strong. So if I do the same thing under ARC (i.e. IBOutlet UIButton *button; ), does this mean button is a strong reference? or Do I have to explcility define it as weak? In short, does IBOutlet imply __weak? 回答1: The word IBOutlet is actually defined as nothing: #define IBOutlet Xcode just