automatic-ref-counting

ARC - implicit bridging

梦想的初衷 提交于 2020-01-01 12:03:15
问题 If i understood correctly we could classify void * as a "C retainable pointer type". So, assigning it to an Objective-C object will be implicitly bridged. However, compiler raises error that explicit bridging is required. const void * somePtr = (void *)0x12345678; - (void)someMethod:(id)sender { NSObject *obj = (NSObject *)somePtr; } Also, i checked the null pointer constant and it compiles without explicit bridging. NSObject *obj = (void *)0; I am using XCode 4.5(Clang 4.1 (tags/ Apple/clang

Converting NSArray Contents to a varargs (With ARC) For Use With NSString initWithFormat

99封情书 提交于 2020-01-01 08:12:09
问题 We have some code today that takes an NSArray and passes it as a argument list to -[NSString initWithFormat:arguments] and we're trying to get this to work with ARC. Here's the code were using NSString* format = @"Item %s and Item %s"; // Retrieved elsewhere NSArray* args = [NSArray arrayWithObjects:@"1", @"2", nil]; // Retrieved elsewhere // http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html char* argsList = (char*) malloc(sizeof(NSString*) * args.count); [args getObjects

Why should I prefer the unsafe_unretained qualifier over assign for weak referencing properties? [duplicate]

我怕爱的太早我们不能终老 提交于 2020-01-01 07:01:18
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: using ARC, lifetime qualifier assign and unsafe_unretained What's the difference between the two? @property(unsafe_unretained) MyClass *delegate; @property(assign) MyClass *delegate; Both are non-zeroing weak references, right? So is there any reason why I should write the longer and harder to read unsafe_unretained instead of assign ? Note: I know there is weak which is a zeroing reference. But it's only iOS

Do I need ARC keywords for properties that I don't synthesize?

耗尽温柔 提交于 2020-01-01 05:38:07
问题 I have a property that I do not synthesize, instead I create a getter and setter myself. Therefore, the ARC keywords (strong or weak) have no meaning, I assume, so I eliminate them. This works fine on Xcode 4.3, but when my coworker opens them on XCode 4.2 the compiler complains that there is no strong/weak keyword, so I instructed him to meaninglessly enter the keyword back in again. Which is correct (with or without keywords)? To be clear: I have a property like this @property (nonatomic)

Weak self in closures and consequences example

删除回忆录丶 提交于 2020-01-01 04:51:06
问题 I have done abit of research on stackoverflow and apple's documentation about ARC and Weak/Unowned self (Shall we always use [unowned self] inside closure in Swift). I get the basic idea about strong reference cycle and how it is not good as they cause memory leaks. However, I am trying to get my head around when to use Weak/Unowned self in closures. Rather then going into the "theory", I think it would really really help if someone could kindly explain them in terms of the bottom three cases

ARC App Crashes when accessing @property form ARC static lib

本小妞迷上赌 提交于 2020-01-01 02:44:12
问题 I have a ARC (automatic-reference-counting) app that builds a static library (also ARC). The app will launch fine but when the an action is performed that reads or writes to a @property in the static library the app will crash with this error: dyld: lazy symbol binding failed: Symbol not found: _objc_setProperty_nonatomic Referenced from: /var/mobile/Applications/0E7ADBB4-FFE5-4CEB-B418-8A35A92E99D4/MyApp.app/MyApp Expected in: /usr/lib/libobjc.A.dylib dyld: Symbol not found: _objc

objective-c ARC readonly properties and private setter implementation

孤街醉人 提交于 2019-12-31 09:11:27
问题 Prior to ARC, if I wanted a property to be readonly to using it but have it writeable within the class, I could do: // Public declaration @interface SomeClass : NSObject @property (nonatomic, retain, readonly) NSString *myProperty; @end // private interface declaration @interface SomeClass() - (void)setMyProperty:(NSString *)newValue; @end @implementation SomeClass - (void)setMyProperty:(NSString *)newValue { if (myProperty != newValue) { [myProperty release]; myProperty = [newValue retain];

Manual retain with ARC

谁说我不能喝 提交于 2019-12-31 08:57:08
问题 Before ARC I had the following code that retains the delegate while an async operation is in progress: - (void)startAsyncWork { [_delegate retain]; // calls executeAsyncWork asynchronously } - (void)executeAsyncWork { // when finished, calls stopAsyncWork } - (void)stopAsyncWork { [_delegate release]; } What is the equivalent to this pattern with ARC? 回答1: Why not just assign your delegate object to a strong ivar for the duration of the asynchronous task? Or have a local variable in

Swift class de-initialized at end of scope instead of after last usage

纵饮孤独 提交于 2019-12-31 06:22:43
问题 I've asked this question asking about the guarantees of the lifetime of a reference in a local variable and was referred to this thread in which the exact semantics of the lifetime of references to class instances were discussed. AFAICT from that thread, a class instance may be de-initialized right after the last usage of a variable containing the last reference, even before other expressions in the same statement are evaluated. It is argued there that allowing this behavior is necessary to

Switching the non ARC project into ARC

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-31 06:07:08
问题 I am new to iphone development. I have learnt that ARC is a new feature introduced in IOS now . My question is, I have an old Non ARC project with the release written manually, is it possible to switch this project from non ARC to ARC ? Thanks, Raj 回答1: Make sure you are using version control, then use: Edit > Refactor > Convert to Objective-C ARC… 来源: https://stackoverflow.com/questions/12171922/switching-the-non-arc-project-into-arc