automatic-ref-counting

How to force xcode to use ARC on a specific file?

谁都会走 提交于 2019-12-03 15:35:50
问题 My project contains XMPPFramework which contains a file that has to be used with ARC. But my project is Non ARC and cannot be converted due to certain other libraries linked to it. How do I force the compiler to use ARC only on a certain class ? 回答1: It is the inverse problem of this question. The difference is that you would use -fobjc-arc instead of -fno-objc-arc . 来源: https://stackoverflow.com/questions/13392521/how-to-force-xcode-to-use-arc-on-a-specific-file

Creating a ZIP file from a folder in documents directory - Objective C (ARC)

偶尔善良 提交于 2019-12-03 15:19:16
I have an iPhone application that I have developed using ARC. I have a folder that contains a heap of images in my documents directory that I need to zip up and e-mail. My project uses ARC. Does anyone have any example code/links to a resource that would be helpful to me? I've been raking around online and what I can find is not compatible with ARC - even when it claims to be. iPhone Developer Download and drag the Objective-Zip, MiniZip and ZLib drag in to your project from this link http://code.google.com/p/objective-zip/downloads/list (Objective-zip). import the files: ZipFile.h,

Strange ARC issue not releasing ivar in UIView subclass [duplicate]

梦想与她 提交于 2019-12-03 15:17:59
Possible Duplicate: Why is object not dealloc'ed when using ARC + NSZombieEnabled I've got a very strange issue I'm seeing at the moment in a project. Put simply I have ViewA which owns ViewB ( strong property). ViewA creates its ViewB in its initialiser. Both objects are subclasses of UIView . I have overridden dealloc in both and put a log line and a break point to see if they get hit. It seems that ViewA 's dealloc is being hit but not ViewB 's. However if I put in a self.viewB = nil in the dealloc of ViewA then it is hit. So basically it's something like this: @interface ViewA : UIView

Must I use __bridge or __bridge_retained if I'm bridging an autoreleased object to Core Foundation?

梦想与她 提交于 2019-12-03 14:55:39
The ARC Migration Tool is having trouble with this: NSURL *fileURL = [NSURL fileURLWithPath:path]; AudioFileOpenURL((CFURLRef)fileURL, kAudioFileReadPermission, 0, &fileID); In particular, it isn't sure about if it should do a __bridge or __bridge_retained. And I'm either. -fileURLWithPath returns an autoreleased object, and in this place I'm not the owner of fileURL. But at the same time, the object has a retain count of at least +1. I'd bet this has to be done with __bridge only. You want to use the regular __bridge cast only for this. You would use __bridge_retained only if you want to

Singleton in Interface Builder with ARC

守給你的承諾、 提交于 2019-12-03 14:45:40
My question is quite similar to this one: Use Singleton In Interface Builder? The only difference is that I use ARC. So, if simplified, my singleton looks like that: Manager.m @implementation Manager + (instancetype)sharedManager { __strong static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } @end So the question is if it's possible to adopt it for Interface Builder still being with ARC? Of course, I understand that it might be simpler just to rewrite that class without ARC so the

Core Data attribute changes to nil (ARC related?)

♀尐吖头ヾ 提交于 2019-12-03 14:14:24
I have some Core Data functionality that was working fine until some recent (seemingly unrelated) changes were made. Now I'm getting problems where all the attributes belonging to a particular NSManagedObject subclass instance are suddenly returning nil. Let's say my NSManagedObject subclass is called Foo and it has only one attribute called value. Once I realised value was somehow becoming nil I went and setup the following category to monitor changes to value. @implementation Foo (Debug) - (void)setValue:(NSDate *)value { [self willChangeValueForKey:@"value"]; [self setPrimitiveValue:value

Weak self in closures and consequences example

試著忘記壹切 提交于 2019-12-03 13:07:36
I have done abit of research on stackoverflow and apple's documentation about ARC and Weak/Unowned self ( Shall we always use [unowned self] inside closure in Swift ). I get the basic idea about strong reference cycle and how it is not good as they cause memory leaks. However, I am trying to get my head around when to use Weak/Unowned self in closures. Rather then going into the "theory", I think it would really really help if someone could kindly explain them in terms of the bottom three cases that I have. My questions is Is it OK to put weak self in all of them (I think for case two there is

Setting the contents of a CALayer to a CGImageRef on iOS with ARC on

て烟熏妆下的殇ゞ 提交于 2019-12-03 13:01:51
The following code compiles fine with manual memory management, but fails under ARC: CALayer *layer = [CALayer layer]; layer.contents = [[UIImage imageNamed:@"dial.png"] CGImage]; The error is: Automatic Reference Counting Issue: Implicit conversion of a non-Objective-C pointer type 'CGImageRef' (aka 'struct CGImage *') to 'id' is disallowed with ARC How can I get this running with ARC? CoreFoundation objets aren't managed by ARC. ARC only works with Objective-C objets and does not implicitly know how to transfer the ownership when casting from (or to) an non-object pointer type. You need to

blocks and ARC - copy or crash with release build (caused by optimization level)

巧了我就是萌 提交于 2019-12-03 12:41:31
I'm using Xcode 4.3.3 and developing for iOS 5.0+. In development of an ARC iOS application, I've started using blocks as a callback mechanism for asynchronous operations. The app works fine in the simulator and on the device. Then I ran it the profiler for the first time, and it started crashing on me nearly right away - in particular, an EXC_BAD_ACCESS when trying to invoke the first callback block. After a little investigation, it was clear the difference in behavior was because the profiler runs in "Release mode" by default - in particular, with Optimization Level set to "Fastest, Smallest

Objective-C classes in structs with ARC

旧时模样 提交于 2019-12-03 12:32:59
I tried making a struct with classes in it like: struct my_struct { NSString *string; // more fields }; To my surprise, Objective-C++ allowed this with ARC enabled. How will it manage the string? It can easily retain in each assignment but release is the problem. It can add a destructor with release in it, but this will make the struct non-trivial. It can also make this not retain or release, but to do so there should be unsafe_unretained. From my observation nothing crashes when using this, but I would like to know what really happens here. See 4.3.5 of the ARC docs : 4.3.5. Ownership