automatic-ref-counting

Removing observers in post-ARC Cocoa

邮差的信 提交于 2019-12-10 17:44:04
问题 So far I have been removing observers (notifications or KVO) in the dealloc. Since dealloc is gone in ARC, what's the recommended way to do this? 回答1: -dealloc is not gone under ARC. The ivar-releasing and super-calling aspects are handled automatically, allowing you to omit it if that's all you were going to do, but you should still implement it for other things if it makes sense to do so. 来源: https://stackoverflow.com/questions/7827953/removing-observers-in-post-arc-cocoa

Apple PrefPane example fails to build with clang error objecting to both -fobjc-arc and -fobjc-gc

*爱你&永不变心* 提交于 2019-12-10 15:29:14
问题 I'm trying to build a preference pane as a part of learning OS X development. After downloading Apple's preference pane example code and trying to build the project I get the following error: clang: error: cannot specify both '-fobjc-arc' and '-fobjc-gc' Turning off garbage collection in Build Settings allows the project to build properly, but once the preference pane example is installed on the local machine it won't start saying, "You can’t open PrefsPane preferences because it doesn’t work

Iterate array of weak references where objects conform to a protocol in Swift

那年仲夏 提交于 2019-12-10 15:16:37
问题 I want to store objects in an array, where objects are weak, and conforms to a protocol. But when I try to loop it, I get a compiler error: public class Weak<T: AnyObject> { public weak var value : T? public init (value: T) { self.value = value } } public protocol ClassWithReloadFRC: class { func reloadFRC() } public var objectWithReloadFRC = [Weak<ClassWithReloadFRC>]() for owrfrc in objectWithReloadFRC { //If I comment this line here, it will able to compile. //if not I get error see below

How to zeroing weak references under non-ARC?

孤街醉人 提交于 2019-12-10 13:57:09
问题 I don't like ARC. But the most important feature of ARC, zeroing weak reference, is missing under non-ARC. Currently I'm using MAZeroingWeakRef, it works, but hacky, sometimes makes codes redundant. Any other ways for zeroing weak references? 回答1: Implementing zeroing weak reference is not hard. All what you have to do is just tracking all referencing pointers - store them in a collection - and assigning NULL when pointing object is being deallocated. Anyway, doing all these things manually

When a view controller is dismissed, should it empty the memory?

拥有回忆 提交于 2019-12-10 13:43:20
问题 I'd like to learn about memory management in Objective-C which I find not that easy because I'm fairly new at Objective-C and ARC and I'm mostly used to script languages for which I don't have to deal that much (or not at all) with memory management. The app I'm working on is presenting a viewController (with xib file attached) from code after the press of a button. In this view controller I have several views instantiated; I record a sequence of images (photo's from the camera, saved to disk

Why a keyword “strong” is used on a property in non-ARC environment?

你说的曾经没有我的故事 提交于 2019-12-10 13:23:24
问题 I just started to develop with with Xcode 4.2 and iOS5. After creating empty Tabbed application project, I have noticed that a new keyword "strong" is used on properties. I read on this post about it being related to retain replacement in ARC environment, but it's not the case because I didn't checked "Use Automatic Reference Counting" check box. 回答1: The keyword "Strong" is a synonym for "retain" in non-ARC environments. For ARC-envs read up here: http://clang.llvm.org/docs

Tool for transitioning to ARC

只愿长相守 提交于 2019-12-10 13:08:46
问题 I want to transition my App to ARC . I can change Objective-C Automatic Reference Counting to YES but that does not automatically remove release s retain s etc. The Transitioning to ARC Release Notes states: Xcode has a new tool that automates the mechanical parts of the ARC conversion (such as removing retain and release calls) and helps you to fix issues the migrator can’t handle automatically. The migration tool converts all files in a project to use ARC. You can also choose to use ARC on

Memory Leak with ARC

百般思念 提交于 2019-12-10 13:05:33
问题 +(void)setup { UIImage* spriteSheet = [UIImage imageNamed:@"mySpriteSheet.png"]; CGRect rect; animation = [NSMutableArray arrayWithCapacity:numberOfFramesInSpriteSheet]; int frameCount = 0; for (int row = 0; row < numberFrameRowsInSpriteSheet; row++) { for (int col = 0; col < numberFrameColsInSpriteSheet; col++) { frameCount++; if (frameCount <= numberOfFramesInSpriteSheet) { rect = CGRectMake(col*frameHeight, row*frameWidth, frameHeight, frameWidth); [animation addObject:[UIImage

NSStatusItem appears briefly on launch, but promptly disappears

心不动则不痛 提交于 2019-12-10 12:37:06
问题 I'm starting to get back into Cocoa development after not working on anything for a few months. Originally when I started I was using Snow Leopard and Xcode 3. I'm now running Lion with Xcode 4.2 and I'm running into some issues that I hadn't run into before. I believe it's probably the fact that I've never used ARC before, so I'm sure I'm missing something. I'm trying to create Statusbar application, without a main window, or dock icon. When I run the application the Statusbar icon for my

Why does Xcode create a weak reference for an IBOutlet? [duplicate]

人盡茶涼 提交于 2019-12-10 12:14:23
问题 This question already has answers here : Should IBOutlets be strong or weak under ARC? (11 answers) Closed 5 years ago . I notice when i create a outlet within a story board it generates the following code __weak IBOutlet UILabel *mLabel; . Why is it declaring it as a weak pointer? From my understanding, when the object gets released, all its members will get released too. In most of my code I'm declaring the outlets as strong pointers. Is this going to create problems? 回答1: According to iOS