automatic-ref-counting

Under ARC, are Blocks automatically copied when assigned to an ivar directly?

二次信任 提交于 2019-11-28 08:14:53
Assume the following code under ARC, typedef void (^MyResponseHandler) (NSError *error); @interface MyClass : NSObject { MyResponseHandler _ivarResponseHandler; } - (void)myMethod:(MyResponseHandler)responseHandler { _ivarResponseHandler = responseHandler; ... } Question: Is the block automatically copied to the heap when assigned to the ivar? My previous question implied that it is copied when assigned through a @property . But, today I used the above code and received an EXC_BAD_ACCESS that was fixed by changing to _ivarResponseHandler = [responseHandler copy] . Edit: My previous answer was

Questions about a readonly @property in ARC

99封情书 提交于 2019-11-28 08:09:15
问题 In my interface (.h) file, I have @property(readonly) NSString *foo; and in my implementation (.m) file, I have @synthesize foo; With ARC turned on, the compiler gives me this error: Automatic Reference Counting Issue: ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute. The error goes away if I add a strong , weak , or copy to the property. Why is this? Why would there be any differences between these things for a read-only property,

How to disable ARC for a single file in Xcode 5?

跟風遠走 提交于 2019-11-28 08:03:06
I recently downloaded Xcode 5, and it's now my primary IDE. However, I now need to disable Automatic Reference Counting for a single file in my project. In Xcode 4, I went to the Build Phases tab under my target, and I could double click the on the right side of a row in the Compile Sources section, add -fno-objc-arc to the list of compiler flags, and be off. In 5, however, the column seems to be unclickable: So, how do I do this? Kjuly Well, I just tried and found that you must had dragged the window to a smaller width. You need to drag it back to show the Compiler Flag column: To fix the

Objective C - Custom setter with ARC?

不问归期 提交于 2019-11-28 08:02:35
Here is how I used to write a custom retained setter before: - (void)setMyObject:(MyObject *)anObject { [_myObject release], _myObject = nil; _myObject = [anObject retain]; // Other stuff } How can I achieve this with ARC when the property is set to strong. How can I make sure that the variable has strong pointer? The strong takes care of itself on the ivar level, so you can merely do - (void)setMyObject:(MyObject *)anObject { _myObject = anObject; // other stuff } and that's it. Note: if you're doing this without automatic properties, the ivar would be MyObject *_myObject; and then ARC takes

is it possible to combine non-ARC and ARC project code?

不想你离开。 提交于 2019-11-28 07:38:18
问题 Is it possible to combine ARC and non-ARC projects? I haven't really tried it yet but this is the scenario: We have an old iOS project (non-ARC) with a tab controller. There is a tab from the tab controller that doesn't have any function or view yet. I am making a new project which is related to the old project, and I would like to have it use ARC, if it is possible to combine my new project with the old one and assign my new project's view to the tab. 回答1: Yes of course and it is very easy.

if convert project to Automatic Reference Counting(ARC), Is it still support on iOS 3.X, 4.X?

喜欢而已 提交于 2019-11-28 07:35:29
问题 i not sure about convert project to Automatic Reference Counting(ARC). it still support on iOS 4.X or lower ? thank you 回答1: From what I can gather yes - ARC is done by the compiler and should be thought of as a wizard or helper that checks all of your code and inserts the correct retain and release statements for you. This will therefore be compatible with older iOS runtimes. Edit: IT will support 4.x but not 3.x 回答2: It will support iOS 4 but not iOS 3. Still, there's no full support for

Link Errors with Parse.framework iOS

老子叫甜甜 提交于 2019-11-28 06:58:49
I tried importing the parse framework in my project. I made sure it is liked with my project and I couldn't find anything about whether it is 'arc sensitive' or not. My project is arc based. This is the error I'm getting: Undefined symbols for architecture i386: "_SCNetworkReachabilityCreateWithName", referenced from: -[PFCommandCache init] in Parse(PFCommandCache.o) +[PFInternalUtils(Reachability) isParseReachable] in Parse(PFInternalUtils.o) "_SCNetworkReachabilityGetFlags", referenced from: ___22-[PFCommandCache init]_block_invoke in Parse(PFCommandCache.o) +[PFInternalUtils(Reachability)

Automatic Reference Counting: Pointer to non-const type 'NSError *' with no explicit ownership

一世执手 提交于 2019-11-28 06:46:58
In updating some of my code to be in compatible with the iOS 5 SDK, I attempted to refactor my code by using "Convert to Objective-C ARC" in Xcode and received an error. The error occurs on an instance variable in my .h file. NSError **_error; The error says "Pointer to non-const type 'NSError *' with no explicit ownership." How might I fix this? When storing NSError objects in an instance variable you have to declare it as a simple pointer: @interface Foo : NSObject { NSError *_errror; } NSError ** is only used to indirectly return NSError objects from a method to the caller. It is (probably)

IOS, ARC, Property: (readwrite, nonatomic) vs (radwrite, retain, nonatomic)

烂漫一生 提交于 2019-11-28 06:45:04
问题 I am have read up some tutorials on ARC and am still left a bit confused on properties declarations. I wrote most most my code using the following pattern: @property (readwrite, nonatomic) PlayerData* playerData; @property (readwrite, nonatomic) MusicLayer* musicLayer; @property (readwrite, nonatomic) bool isPowerUpAvailable; Now that I finally started to deal with memory leaks XCode suggested me that in some bits of code I should have added the "retain" keyword in the property declaration.

Set delegates to nil under ARC?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 06:31:38
I'm writing iOS apps using ARC and targeting iOS 5+. Suppose I write a custom view object that has a delegate property. In declaring the delegate property, I make it a weak reference to avoid a retain cycle, so that when the actual delegate object (the controller) is destroyed, my custom view will also be destroyed, as follows: @interface MyCustomView : UIView @property (nonatomic, weak) id<MyCustomViewDelegate> delegate; @end All is good. Ok, so now I'm writing the controller object, and it has references to two view objects: my custom view and an Apple-supplied UIKit view, both of which