automatic-ref-counting

MKMapView still sending messages to delegate after it's superview has been de-alloc'ed

流过昼夜 提交于 2019-12-21 07:35:21
问题 EDIT: changed the title. I didn't know it at the time but this is a duplicate of Why am I crashing after MKMapView is freed if I'm no longer using it? This question is similar to Why is object not dealloc'ed when using ARC + NSZombieEnabled but different enough that I thought it worth throwing out there in case anyone understands and can explain to me what is happening. The other question may be an XCode bug so I presume this could be similar. Scenario: RootViewController has a tableView

Retaining ARC objects in c++ classes

大兔子大兔子 提交于 2019-12-21 07:16:21
问题 I have some code that must remain as c++, but I need to store objective-c objects in these c++ classes. The objects will not be referenced anywhere else while they are stored here, so I can't have them deleted out from under me. Before ARC, I just retained them before putting them into the c++ class, and autoreleased them when they were removed. Everything worked fines. But with ARC, I'm not sure what to do. Is making the c++ variables __unsafe_unretained enough? Doesn't seem like it is

Singleton in Interface Builder with ARC

三世轮回 提交于 2019-12-21 05:08:18
问题 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

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

痴心易碎 提交于 2019-12-21 05:06:08
问题 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. 回答1: Download and drag the Objective-Zip, MiniZip and ZLib drag in to your project from this link http://code.google

iOS ARC - weak and strong properties

孤街醉人 提交于 2019-12-21 05:05:19
问题 I'm trying to understand the way ARC works, and as far as I know, I should be doing something wrong here. This is the code I'm using: Interface: @interface ViewController : UIViewController{ } @property (strong, nonatomic) NSString * myString ; @property (weak, nonatomic) NSString * myPointer ; Implementation: - (void)viewDidLoad{ [super viewDidLoad]; self.myString = @"Hello world!" ; // myString is strong self.myPointer = self.myString ; // myPointer var is weak [self performSelector:

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

荒凉一梦 提交于 2019-12-21 05:01:17
问题 This question already has answers here : Closed 7 years ago . 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

Objective-C ARC and passing C arrays of objects

笑着哭i 提交于 2019-12-21 04:36:17
问题 I'm sorry if this is a bit of a C-noob question: I know I need to swot up on my pointers. Unfortunately I'm on a deadline so don't have time to work through a whole book chapter, so I'm hoping for a bit more targeted advice. I want to store some objective-C objects in a C array. I'm using ARC. If I were on the Mac I'd be able to use NSPointerArray instead, but I'm on iOS and that's not available. I'll be storing a three-dimensional C array: conceptually my dimensions are day, height, and

What are the advantages of declaring method arguments __autoreleasing?

假装没事ソ 提交于 2019-12-21 04:31:12
问题 As per Transitioning to ARC Release Notes: __autoreleasing is used to denote arguments that are passed by reference (id *) and are autoreleased on return. For example: -(BOOL)performOperationWithError:(NSError * __autoreleasing *)error; But what are the advantages of the above comparing to: -(BOOL)performOperationWithError:(NSError * __strong *)error; Update: Several answers refer to the temp var trick compiler does to deal with the mismatch between var and argument as the advantage of _

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

点点圈 提交于 2019-12-21 04:26:28
问题 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. 回答1: You

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

瘦欲@ 提交于 2019-12-21 04:14:21
问题 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? 回答1: CoreFoundation objets aren't managed by ARC. ARC only works with Objective-C objets and does not