1

I have to do some operation on setter method which have weak property attribute. But, I don't know how to do it. Could anybody help me on this?

karthik
  • 125
  • 1
  • 1
  • 5
  • possible duplicate of [What is the correct way to create a custom setter for a weak property in Objective C?](http://stackoverflow.com/questions/15607404/what-is-the-correct-way-to-create-a-custom-setter-for-a-weak-property-in-objecti) – Julien-L May 06 '15 at 05:00

1 Answers1

3

Assuming you declared a weak property in the header like this:

@property (nonatomic, weak) Bar *foo;

you can simply implement the setter method like this:

- (void)setFoo:(Bar *)foo {
    _foo = foo;
    // do your custom things here
}

where _foo is the automatically generated instance variable for your property.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • 1
    Have you tested this code for the case that automatic zeroing of the pointer is still working? – nalexn Apr 05 '14 at 08:25