automatic-ref-counting

Defining a property in iOS class extension

匆匆过客 提交于 2019-12-18 05:43:28
问题 I would like to add a property to UITableView in a Class Extension: @interface UITableViewController () @property NSString *entityString; @end Then I import the extension and then I use entityString property in a subclass of UITableViewController: @implementation CustomerTableViewController - (void)viewDidLoad { self.entityString = @"Customer"; ... [super viewDidLoad]; } ... Apple documentation says: the compiler will automatically synthesize the relevant accessor methods (...) inside the

What is the correct way to create a custom setter for a weak property in Objective C?

我与影子孤独终老i 提交于 2019-12-18 05:38:26
问题 If I declare a property like this: @property(nonatomic,weak) Foo *someProperty; and I then declare a custom setter like so: - (void)setSomeProperty:(Foo *)someProp { _someProperty = someProp; //...more custom stuff } is there anything wrong with this? That is, the compiler should automatically synthesize the _someProperty ivar with the __weak modifier, so just doing the assignment in the setter above should suffice, correct? 回答1: Yes, that's all there is to it. Of course you can specify a

ARC: Setting compiler flags to -fno-objc-arc and build errors

旧时模样 提交于 2019-12-18 04:59:10
问题 Following a stackoverflow topic about disabling ARC compiler mechanism for specific classes, I added the -fno-objc-arc argument to Compiler Flags column under Compile Sources section (Buil Phases tab within TARGETS project). Even if settings have been validated, I'm not able to build my application since the compiler says that retain, release, etc. cannot be used under ARC. How can I fix the above problem? Thank you in advance. 回答1: Did you use the migration tool to perform your migration?

What is an Objective-C “class continuation”?

大城市里の小女人 提交于 2019-12-18 04:53:05
问题 I can't quite figure out what I have seen referred to as an Objective-C "class continuation" . Is this / are these… Ivar(s) declared in the @implementation ( .m ) file? Another name for a class category? (Unlikely, ASFAIK categories cannot have Ivars, period) Another name for a class extension? Something else? That said... What is the scope, lifetime, and usage case for such a thing? Is this an ARC-specific "feature"? Are there specific runtime, or other requirements for their use? Is this an

Include non-ARC library in an ARC app?

喜你入骨 提交于 2019-12-18 04:11:24
问题 So, is it possible? I get this error multiple times: ARC forbids Objective-C objects in structs or unions For example here: typedef struct { BOOL _field1; union { struct { id _field1; id _field2; } _field1; GSEventRef _field2; } _field2; } XXStruct_CKAdxD; 回答1: You need to add -fno-objc-arc to the compiler options for each file that doesn't / can't use ARC. Within Xcode you do this from the 'Compile Sources' build phase of your target. Double click the file and add -fno-objc-arc to the box

when should you use __bridge vs. CFBridgingRelease/CFBridgingRetain?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:56:08
问题 I have this code that uses "__bridge" to cast the ids of colors: CGColorRef tabColor = (5 == 5 ? [UIColor blueColor].CGColor : [UIColor greenColor].CGColor); CGColorRef startColor = [UIColor whiteColor].CGColor; CGColorRef endColor = tabColor; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations); but would: NSArray *colors = [NSArray

I'm writing a Button class in Objective-C with ARC — How do I prevent Clang's memory leak warning on the selector?

只谈情不闲聊 提交于 2019-12-18 03:06:29
问题 I'm writing a simple button class, something like this: @interface MyButton : NSObject { id object; SEL action; } @property(strong) id object; @property SEL action; -(void)fire; @end @implementation MyButton @synthesize object, action; -(void)fire { [object performSelector:action]; } @end I get the following warning from Clang on [object performSelector:action] : PerformSelector may cause a leak because its selector is unknown After some research I see that selectors can belong to families

Do capture lists of inner closures need to redeclare `self` as `weak` or `unowned`?

一笑奈何 提交于 2019-12-18 02:43:16
问题 If I have a closure passed to a function like this: someFunctionWithTrailingClosure { [weak self] in anotherFunctionWithTrailingClosure { [weak self] in self?.doSomething() } } If I declare self as [weak self] in someFunctionWithTrailingClosure 's capture list without redeclaring it as weak again in the capture list of anotherFunctionWithTrailingClosure self is already becoming an Optional type but is it also becoming a weak reference as well? Thanks! 回答1: The [weak self] in

Do capture lists of inner closures need to redeclare `self` as `weak` or `unowned`?

本小妞迷上赌 提交于 2019-12-18 02:43:06
问题 If I have a closure passed to a function like this: someFunctionWithTrailingClosure { [weak self] in anotherFunctionWithTrailingClosure { [weak self] in self?.doSomething() } } If I declare self as [weak self] in someFunctionWithTrailingClosure 's capture list without redeclaring it as weak again in the capture list of anotherFunctionWithTrailingClosure self is already becoming an Optional type but is it also becoming a weak reference as well? Thanks! 回答1: The [weak self] in

Forcing an object to deallocate under ARC

匆匆过客 提交于 2019-12-18 02:41:23
问题 I'm working on an iPad photo collage app that draws perhaps hundreds of UIImageView s on the screen at once. There is a button that lets the user "re-create", which is suppose to run a for loop to [photo removeFromSuperview] on all photos and then initialize a new batch, in that order. I'm using ARC, and my console tells me that my Photo 's dealloc method isn't being called until AFTER the next batch has been drawn, meaning I'm running into memory issues, even though I'm trying to remove the