A question about "self"

I have an IBOutlet in my .h file


@property (nonatomic, strong) IBOutlet UIImageView *myImage;


What is the difference between these assignments?


playerLayer.frame = self.myImage.frame;

playerLayer.frame = myImage.frame;

Replies

The difference is if the compiler complains without it...


See https://stackoverflow.com/questions/24215578/when-should-i-access-properties-with-self-in-swift

there should be no difference.


Unless these lines are inside a block where you redefine an imageView.

Then the first would refer to IBOutlet, the second would efer to the var in the local scope.


Hence, it is good practice to always add self when you want to refer to the class instance.

Just for clarity, you are able to use "myImage.frame;"? Don't you need "_ myImage.frame;"?

The behavior is different with the two lines. The one with self works; the other doesn't. Based on the answers, it is because myImage is an IBOutlet.

Is there a different behavior in Swift and objc ?


self.anOutlet works in Swift.