automatic-ref-counting

Batch adding “-fno-objc-arc” flag to (multiple) source files

你。 提交于 2019-11-27 05:55:05
问题 After converting an Xcode project to ARC (Automatic Reference Counting), I need to disable ARC for some of my source files (mainly third-party code). I know I need to set the "-fno-objc-arc" flag for each of these files, but Xcode doesn't give me a option for batch editing - I need to add this flag to each file manually, which may be tedious if you need to set it for multiple files. Does anyone have a smart approach to this? 回答1: Select the ones you want to add the flag to (using Shift and/or

ASIHTTPRequest / ASIFormDataRequest - referencing request object within blocks under ARC

浪子不回头ぞ 提交于 2019-11-27 05:40:00
问题 Very similar to this question, I am trying to convert a project that uses ASIHTTPRequest & ASIFormDataRequest to ARC. In my view controller classes, I often refer to and use properties of the request object in the completion blocks (looking at the response code, response data etc): __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:SOME_URL]]; [request setCompletionBlock:^{ if([request responseStatusCode] == 200) ....etc When converting to ARC I get

AVAudioPlayer stops playing immediately with ARC

独自空忆成欢 提交于 2019-11-27 05:17:24
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 { [super viewDidLoad]; NSString* recorderFilePath = [NSString stringWithFormat:@"%@/MySound.mp3",

ARC __bridge modifiers demystified

≡放荡痞女 提交于 2019-11-27 05:11:42
问题 I was asked recently by one of my friends about the new bridge modifiers that became active under ARC. He asked me if I knew which ones to use in specific times and what the difference between the different __bridge modifiers were. He asked me,"so how do they work, when do I use them, how do I use them , and how do they work "under the hood" "? Note: This was supposed to be a "Share your knowledge" type of question, where I answered the question myself, but I'm not sure I set it up properly.

Find where object is retained with ARC

房东的猫 提交于 2019-11-27 05:04:43
问题 I have an object that is being retained more than necessary (most likely due to a property that is strong instead of weak ). Big codebase, so it's hard to find where. How can I find all the lines in which this object is being retained when using ARC? If I weren't using ARC I guess I could simply override retain and check from where it's called. Can I do something similar with ARC? 回答1: To track growth of an application, Heapshot Analysis has proven very effective. It will capture both true

Generic typeof for weak self references

為{幸葍}努か 提交于 2019-11-27 05:04:21
问题 I am trying to figure out a way to use typeof to create a weak reference to self for use in blocks to avoid retain cycles. When I first read about this it seems that the convention was to use __block typeof(self) bself = self; , which compiles but using __block to avoid retain cycles doesn't work anymore and __weak should be used instead. However __weak typeof(self) bself = self; results in an error: The type 'typeof (self)' (aka 'TUAccountsViewController *const __strong') already has

Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

元气小坏坏 提交于 2019-11-27 04:56:38
问题 I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects." This is my code: .h @interface ViewController : UIViewController { NSString *newTitle; } @property (strong, nonatomic) NSString *newTitle; .m @synthesize newTitle; Does anyone

How to automatically convert Manual Retain-Release code to ARC?

断了今生、忘了曾经 提交于 2019-11-27 04:39:07
问题 I have thousands of line of code written for iOS 4. The codebase contains many calls to retain and release , which cause errors when the project is updated to iOS 5 and ARC. Is there a way to automatically convert Manual Retain-Release (MRR) code to Automatic Reference Counting (ARC)? 回答1: In Xcode 6+, the command is now: Edit > Convert > To Objective-C ARC... 回答2: From the Xcode 4.2 release notes: To initiate the process, enable Continue building after errors in the General Preferences pane,

What are the advantages and disadvantages of using ARC? [closed]

喜欢而已 提交于 2019-11-27 04:13:23
问题 What are the advantages and disadvantages of using the new automatic reference counting (ARC) memory management style in an iOS project? Can you choose not to use ARC when developing with the iOS 5.0 SDK? Do you recommend ARC or manual reference counting (MRC) for a new project? Will an application using ARC be able to run on older OS versions than iOS 5.0? 回答1: What are the advantages and disadvantages of using the new automatic reference counting (ARC) memory management style in an iOS

Zeroing Weak References in ARC

扶醉桌前 提交于 2019-11-27 04:10:33
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. It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is