0

I am reading a this tutorial in which he declared a method in cell .h file which accept a block but did not implement the method in .m class, he declared a private property with same name as method @property (copy, nonatomic) void (^didTapButtonBlock)(id sender);

what is this practice? only declaring a method in .h and making a private property in .m

I tried to do it simply like this

I created a method in .h file

-(void)xyz:(NSString*)string;

in .m file

@property (nonatomic, strong) NSString *string;

But Xcode giving warning Method definition for 'xyz' not found

Kindly tell what is going behind the scene?

Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
S.J
  • 3,063
  • 3
  • 33
  • 66

1 Answers1

3

He's exposing the setter method for the block variable, but keeping the getter private, if you notice, the method have the word set, which is the setter method for a property

This is how you can do the same:

-(void)setXyz:(NSString*)xyz;

and in .m:

@property (nonatomic, strong) NSString *xyz;

This way is to make sure other class cannot get the property instance, but can give it value

Tj3n
  • 9,837
  • 2
  • 24
  • 35