-1

As the title explained, if I control drag a component in xib file towards the .h file to conveniently create an outlet, like doublePicker or something else, the xcode will help create statement in viewDidUnloaded: method like this:

[self setDoublePicker:nil];

What is the difference between that and:

self.doublePicker = nil;

Which one performs better?

Venk
  • 5,949
  • 9
  • 41
  • 52
Warbean
  • 547
  • 2
  • 5
  • 19

4 Answers4

2
Foo *foo = [[Foo alloc] init];
foo.bar = YES;
[foo setBar:YES];

The last two lines will compile exactly the same. The only thing that changes this is if a property has a getter and/or setter attribute specified; however, all it does is change what message gets sent, not whether a message is sent:

if ([someView isEmpty]) { /* ... */ }
if (someView.empty) { /* ... */ }

Both the lines gives same result. . once refere this one for better understanding Dot notation.

Balu
  • 8,470
  • 2
  • 24
  • 41
1

They are equivalent. Setting a value using an Objective-C property foo = nil is equivalent to calling setFoo:nil. See:

Stuart M
  • 11,458
  • 6
  • 45
  • 59
1

in Simple first one is calling method which name is setDoublePicker
and Second is you set self.doublePicker as nil.

For more info read this Question Difference between self.var and simply var.

And also read this official document.

Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137
1

Both are same if you are not using any custom setter or getter methods for the instance variable. If you are using any custom setter or getter then you will get a warning on below code

[self setDoublePicker:nil ];
Exploring
  • 925
  • 6
  • 18