automatic-ref-counting

Explanation of strong and weak storage in iOS5

[亡魂溺海] 提交于 2019-11-26 11:30:02
I am new to iOS5 development and using objective-c. I have trouble understanding the difference between strong and weak storage. I have read the documentation and other SO questions, but they all sound identical to me with no further insight. I read the documentation: Transitioning To ARC - it references to iOS4 terms of retain, assign, and release; which confuses me. Then I look into Open U CS193p, where it differentiates strong and weak: Strong : "keep this in the heap until I don't point to it anymore" Weak : "keep this as long as someone else points to it strongly" Aren't the two

AVAudioPlayer stops playing immediately with ARC

為{幸葍}努か 提交于 2019-11-26 11:29:56
问题 I am trying to play an MP3 via AVAudioPlayer which I thought to be fairly simple. Unfortunately, it\'s not quite working. Here is all I did: For the sake of testing, I created a new iOS application (Single View) in Xcode. I added the AVFoundation framework to the project as well as the #import <AVFoundation/AVFoundation.h> to the ViewController.m I added an MP3 File to the Apps \'Documents\' folder. I changed the ViewControllers viewDidLoad: to the following: Code: - (void)viewDidLoad {

Always pass weak reference of self into block in ARC?

纵然是瞬间 提交于 2019-11-26 11:27:24
I am a little confused about block usage in Objective-C. I currently use ARC and I have quite a lot of blocks in my app, currently always referring to self instead of its weak reference. May that be the cause of these blocks retaining self and keeping it from being dealloced ? The question is, should I always use a weak reference of self in a block ? -(void)handleNewerData:(NSArray *)arr { ProcessOperation *operation = [[ProcessOperation alloc] initWithDataToProcess:arr completion:^(NSMutableArray *rows) { dispatch_async(dispatch_get_main_queue(), ^{ [self updateFeed:arr rows:rows]; }); }];

Zeroing Weak References in ARC

偶尔善良 提交于 2019-11-26 11:06:00
问题 If my reading of Mike Ash\'s \"Zeroing Weak References\" writeup is correct, weak references are like assign references without ARC. However, if the referenced object is deallocated, instead of getting a \"dangling pointer\" (meaning a pointer that points to a deallocated object), the pointer gets set to nil . Is this right, and does this happen with any property marked weak or assign (when ARC is active)? If this is correct, this would eliminate a lot of SIGABRTs. 回答1: It's mostly right, but

How to enable ARC for a single file

淺唱寂寞╮ 提交于 2019-11-26 10:48:51
问题 I want to bring a single Objective-C class written using ARC into an old project. The internet provides many references for how to enable ARC for your project and then disable it for single files but I want to do the opposite. I want to leave the project as it is, i.e. using manual reference counting, and then enable ARC just for the new file. (My searches have failed me here.) Is this possible? How? 回答1: Add the -fobjc-arc flag to any files for which you'd like to enable ARC, as described in

How to disable Xcode4.2 Automatic Reference Counting

↘锁芯ラ 提交于 2019-11-26 10:34:42
问题 Today, I have update my xCode to 4.2 version, And I want to disable the ARC, I also search with the google. but can\'t fix my problem. According the search results, In the target setting, I can\'t find the \'Objective-C Automatic reference counting\' item, So have no chance to set it to NO. I find the item one by one, and also use the search field. And one know the newest Xcode4.2 ,how to disable the ARC for the project, not for the specific file. Thanks very much. 回答1: Click on you project,

KVO and ARC how to removeObserver

僤鯓⒐⒋嵵緔 提交于 2019-11-26 10:27:13
问题 How do you remove an observer from an object under ARC? Do we just add the observer and forget about removing it? If we no longer manage memory manually where do we resign from observing? For example, on a view controller: [self.view addObserver:self forKeyPath:@\"self.frame\" options:NSKeyValueObservingOptionNew context:nil]; Previously, I would call removeObserver: in the view controller\'s dealloc method. 回答1: You still can implement -dealloc under ARC, which appears to be the appropriate

ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject

梦想的初衷 提交于 2019-11-26 10:23:38
问题 I\'m using AddThis to add sharing options in my iOS app. I have imported the classes and added the -fno-objc-arc flag to all the imported classes since they don\'t use ARC. However, when I try to run the app I get a slew of Parse Issues such as: Expected identifier or \'(\' Unknown type name \'NSString\' Unknown type name \'Protocol\' ... These errors occur in NSObjCRuntime, NSZone, and NSObject. I have the requisite frameworks included as well. Any ideas? Including this image if it helps:

Weak and strong property setter attributes in Objective-C

*爱你&永不变心* 提交于 2019-11-26 10:07:06
问题 What is the difference between weak and strong property setter attributes in Objective-C? @property(retain, [weak/strong]) __attribute__((NSObject)) CFDictionaryRef myDictionary; What is the impact and benefit? I heard that weak is not available on iOS 4 and we need to use assign. Is weak similar to assign? 回答1: You either have ARC on or off for a particular file. If its on you cannot use retain release autorelease etc... Instead you use strong weak for properties or __strong __weak for

With ARC, what&#39;s better: alloc or autorelease initializers?

血红的双手。 提交于 2019-11-26 09:23:13
问题 Is it better (faster & more efficient) to use alloc or autorelease initializers. E.g.: - (NSString *)hello:(NSString *)name { return [[NSString alloc] initWithFormat:@\"Hello, %@\", name]; } OR - (NSString *)hello:(NSString *)name { return [NSString stringWithFormat:@\"Hello, %@\", name]; // return [@\"Hello, \" stringByAppendingString:name]; // even simpler } I know that in most cases, performance here shouldn\'t matter. But, I\'d still like to get in the habit of doing it the better way. If