automatic-ref-counting

Custom Getter & Setter iOS 5

跟風遠走 提交于 2019-11-28 17:13:44
I want to override the getter and setter in my ObjC class using ARC. .h File @property (retain, nonatomic) Season *season; .m File @synthesize season; - (void)setSeason:(Season *)s { self.season = s; // do some more stuff } - (Season *)season { return self.season; } Am I missing something here? Yep, those are infinite recursive loops. That's because self.season = s; is translated by the compiler into [self setSeason:s]; and return self.season; is translated into return [self season]; Get rid of the dot-accessor self. and your code will be correct. This syntax, however, can be confusing given

UIViewController does not retain its programmatically-created UISearchDisplayController

試著忘記壹切 提交于 2019-11-28 16:46:37
问题 In the UIViewController documentation about the searchDisplayController property 1 it says: If you create your search display controller programmatically, this property is set automatically by the search display controller when it is initialized. And when I create my UISearchDisplayController thusly: [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease]; -[UIViewController searchDisplayController] is not nil . However, it is nilled out after the

Possible to pass [self anyFunction] in blocks without __weak object (iOS 5 + ARC)

假如想象 提交于 2019-11-28 16:34:05
Is it possible to pass [self anyFunction] in blocks without a __weak object from self? As an example this is valid code from the System Framework: [UIView animateWithDuration:0.8 animations:^{ //Do animationStuff } completion:^(BOOL finished) { [self anyFunction]; }]; You can pass [self anyFunction] in the completion block without a warning. But if you write your own method with a completion block, the following warning occurs: capturing 'self' strongly in this block is likely to lead to a retain cycle . A working solution is quite simple (iOS 5 + ARC). Before the block declare: __weak MyClass

ARC, ivars in Blocks and Reference Cycles via Captured Self

本小妞迷上赌 提交于 2019-11-28 16:29:47
问题 I’m working in a pure iOS5/ARC environment, so I can use __weak references as needed. I do reference ivars in a block in many situations, most notably, animation blocks that move views around, which are properties of say, my view controller class. My question: In the most trivial use of ivars in a block, am I creating a reference cycle? Do I need to use the __weak self / strong self technique everytime I write a block that manipulates instance variables of the containing object? I’ve been re

Understanding retain cycle in depth

会有一股神秘感。 提交于 2019-11-28 16:25:45
问题 Lets say we have three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. What will happen in this case ? 回答1: Unless there is some other reference to the parent or child, they both become orphaned. But the retain cycle between the parent and child prevent either from being released and they become wasted memory. A child should never retain a parent. If anything, use

Displaying a Cocoa Window as a Sheet in Xcode 4 (OSX 10.7.2) with ARC

蓝咒 提交于 2019-11-28 15:48:20
问题 I'm trying to get a Login Window to display as a sheet from my MainWindow, but whenever I try to implement the AppKit methods an error always pops up for various indistinguishable reasons. None of the online guides out there are working, when i apply their code / adapted classes to my own project they never work. Most of the guides are heavily outdated, including the Apple Documentation. And none of them seem to be compatible with Automatic Reference Counting. Or the Xcode 4 interfaces. Would

Weak Reference to NSTimer Target To Prevent Retain Cycle

白昼怎懂夜的黑 提交于 2019-11-28 15:43:06
I'm using an NSTimer like this: timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(tick) userInfo:nil repeats:YES]; Of course, NSTimer retains the target which creates a retain cycle. Furthermore, self isn't a UIViewController so I don't have anything like viewDidUnload where I can invalidate the timer to break the cycle. So I'm wondering if I could use a weak reference instead: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:weakSelf selector:@selector(tick) userInfo:nil repeats:YES]; I've heard that the timer must be

release method deprecated

↘锁芯ラ 提交于 2019-11-28 14:14:38
When has happen to the release method? I always release a memory allocation when I am done with it and now it seems that the method has been deprecated. Or maybe it does not work for some objects? Anyway, this is what I did: Customer *aCustomer = [[Customer alloc] init]; ... [aCustomer release]; and I get an error there... Anyone care to explain why I get an error now that I release my memory? The error message is: 'release' in unavailable: not available in automatic reference counting mode ARC forbids explicit message send of 'release' Ilanchezhian If you have enabled the 'ARC', then you don

Xcode 4.2 with ARC: will my code run even on iOS devices with firmware older than 5.0?

落花浮王杯 提交于 2019-11-28 12:35:15
I updated my Xcode to 4.2 version, which includes the ARC technology. It seems to be a good thing, but if I enable ARC and edit my code according to Apple's suggestions, will my app build&run even on 4.3.x devices? Or only for iOS 5 ones? Joshua Weinberg ARC applications will run on OS 4.0 (4.3?) and up. On 4.3 you will lose the zeroing-weak-reference feature though. So if you rely on __weak, you shouldn't expect to work properly on < 5.0. 来源: https://stackoverflow.com/questions/7768861/xcode-4-2-with-arc-will-my-code-run-even-on-ios-devices-with-firmware-older-tha

using ARC, lifetime qualifier assign and unsafe_unretained

跟風遠走 提交于 2019-11-28 11:18:48
i'm a little confused about these two qualifiers... With ARC instead of using weak (i.e. if I need support iOS 4) I can use unsafe_unretained losing the auto-nil features... the final result seems to be similar to assign . Can I exchange unsafe_unretained with assign ? Are these qualifiers the same thing ? It would be really interesting any link of Apple documentation on this argument... I can find only a few rows here Clang's technical specification of ARC goes into much more detail about how the qualifiers work. But, to answer your question: assign and __unsafe_unretained are not the same