declared-property

Why does Apple use assign rather than weak to store a delegate?

心已入冬 提交于 2020-01-04 10:19:00
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

Why does Apple use assign rather than weak to store a delegate?

走远了吗. 提交于 2020-01-04 10:18:08
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

Assignment to ivar in a Block via weak pointer

断了今生、忘了曾经 提交于 2019-12-30 03:20:09
问题 I have a read-only property isFinished in my interface file: typedef void (^MyFinishedBlock)(BOOL success, NSError *e); @interface TMSyncBase : NSObject { BOOL isFinished_; } @property (nonatomic, readonly) BOOL isFinished; and I want to set it to YES in a block at some point later, without creating a retain cycle to self : - (void)doSomethingWithFinishedBlock:(MyFinishedBlock)theFinishedBlock { __weak MyClass *weakSelf = self; MyFinishedBlock finishedBlockWrapper = ^(BOOL success, NSError *e

Is there a difference between setting a property with the dot or the bracket syntax?

☆樱花仙子☆ 提交于 2019-12-29 08:00:47
问题 Given the property declaration below, does method (A) work in exactly the same way as method (B)? I just want to check that self.yellowViewController = yellcon_New; is going via my setter, so that the old objects gets released and the new one retained. // INTERFACE @property(nonatomic, retain) YellowViewController *yellowViewController; // IMPLEMENTATION (A) self.yellowViewController = yellcon_New; // IMPLEMENTATION (B) [self setYellowViewController:yellcon_New]; 回答1: All of this is correct :

myView.frame.origin.x = value; does not work - But why?

馋奶兔 提交于 2019-12-17 10:27:09
问题 I know that I can't use this: myView.frame.origin.x = 25.0; and that I have to use this instead: CGRect myFrame = myView.frame; myFrame.origin.x = 25.0; myView.frame = myFrame; And I'm doing it all the time, but I don't know why I must do it that way. I would like to fill that gap in my understanding. Can someone explain ? Nowadays Xcode gives you "Expression not assignable". Some time ago you got a compile error "Lvalue required as left operand of assignment". 回答1: There are two distinct dot

Compiler error “use of undeclared identifier” when I remove my @synthesize statements

空扰寡人 提交于 2019-12-12 13:01:02
问题 With the latest LLVM build, the requirement for synthesizing properties has been removed. Therefore I was able to remove all my @synthesize statements except for the ones for NSFetchedResultsController . Does anyone know why the compiler is warning me when I remove the @synthesize fetchedResultsController; line? Error: Use of undeclared identifier "fetchedResultsController", did you mean _fetchedResultsController? This is my code: @property (nonatomic, strong) NSFetchedResultsController

Properties don't get initialized in iOS 7

假如想象 提交于 2019-12-12 01:36:09
问题 I'm developing for iOS 7 but I still have to manually write getters otherwise my properties just don't get initialized. I tried to manually synthesize those properties, even though that shouldn't be needed anymore, but that doesn't do it. In my view controller below, I use the property motionTracker , which never gets initialized. I have the same issue with all my projects, so I know it's a misunderstanding on my part. #import "ViewController.h" #import "TracksMotion.h" @interface

When to use strong or weak for properties

妖精的绣舞 提交于 2019-12-10 10:53:14
问题 I have a table view as an IBOutlet , and by default XCode sets its property to be strong rather than weak . Sometimes I get a "recieved memory warning" message. So I tried to change many properties from strong to weak , but it doesn't seem to affect the process and things work smoothly. Should I set the outlets to weak, or am I wrong? And most importantly, should I set ALL properties to nil in the viewDidUnload method, or only the IBOutlet s? 回答1: You should set only Strong properties to nil

When to use strong or weak for properties

孤街醉人 提交于 2019-12-06 11:42:58
I have a table view as an IBOutlet , and by default XCode sets its property to be strong rather than weak . Sometimes I get a "recieved memory warning" message. So I tried to change many properties from strong to weak , but it doesn't seem to affect the process and things work smoothly. Should I set the outlets to weak, or am I wrong? And most importantly, should I set ALL properties to nil in the viewDidUnload method, or only the IBOutlet s? Rohit Gupta You should set only Strong properties to nil in viewDidUnload . Weak Properties are automatically set to Nil if the destination object is

Why does Xcode automatically create variables with underscores?

北战南征 提交于 2019-12-06 05:36:54
问题 Why in the newest version of Xcode (dp-4) are variables declared with retain,nonatomic made to use the underscore before the variable name? Does this create some sort of type safety? For example, I create a property: @property (retain, nonatomic) IBOutlet UILabel *name; Unless I change the variable inside the dealloc to not have the _, I have to do: @synthesize name = _name; Why is this? 回答1: Mark Dalrymple, who's way smarter than I am, wrote a blog post at Big Nerd Ranch about this very