1

I do not understand what mean this style and are there any benefits for standard setter/getter?

- (UIViewController*)myVC {
return objc_getAssociatedObject(self, kMJPopupViewController);
}

- (void)setMyVC:(UIViewController *) myVC {
objc_setAssociatedObject(self, kMyVC, myVC, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3358463
  • 125
  • 15

1 Answers1

1

You can only have member variables -- which back "standard" properties' getters and setters -- in the main @interface and in the class extension (the category with no name). Using associated objects is especially useful in a class's category because it lets you pretend the class has a backing variable anyway.

See also libextobjc, which has a synthesizeAssociation() macro, which makes it near trivial to add @properties inside categories.

EthanB
  • 4,239
  • 1
  • 28
  • 46