Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the "didset of swift" in objective-c?

Tags:

Swift (from the book 《iOS Animations by Tutorials:Chapter 12》 released by http://www.raywenderlich.com/):

let photoLayer = CALayer()  @IBInspectable   var image: UIImage! {     didSet {       photoLayer.contents = image.CGImage     } } 

How can I implement the above syntax in objective-c? I know only to set the property of photoLayer and image like below:

@property (strong, nonatomic) CALayer *photoLayer; @property (strong, nonatomic) IBInspectable UIImage *image; 

But i do not know how to implement didset{...} parts using objective-c syntax, please help!

like image 925
codingiran Avatar asked Sep 24 '15 08:09

codingiran


People also ask

What is didSet in Swift?

didSet is called right after the data is stored and it has a default constant oldValue which shows the previous value that is overwritten.

What is willSet and didSet?

willSet is called just before the value is stored. didSet is called immediately after the new value is stored.


1 Answers

override the setter and implement the setter yourself.

- (void)setImage:(UIImage *)image {     if (_image != image) {         _image = image;         photoLayer.contents = image.CGImage;     } } 
like image 158
Daij-Djan Avatar answered Sep 29 '22 11:09

Daij-Djan