我们什么时候在类或其方法中使用self这个词,而不仅仅使用属性名?
例如,在下面的代码中,其中一行是“self.ageLabel?.text = self.video?.timespan”
为什么不使用“ageLabel?.text = video?.timespan”?或者这是同一件事,它归结为偏好?
import UIKit
class VideoTableViewCell: ContactTableViewCell {
var video: Video?
@IBOutlet weak var picture: UIImageView?
@IBOutlet weak var titleLabel: UILabel?
@IBOutlet weak var ageLabel: UILabel?
@IBOutlet weak var lawerLabel: UILabel?
override func awakeFromNib() {
super.awakeFromNib()
if UIScreen.mainScreen().isSmall() {
self.updateFont(self.titleLabel)
self.updateFont(self.ageLabel)
self.updateFont(self.lawerLabel)
self.updateButtonFont(self.phoneButton)
self.updateButtonFont(self.emailButton)
}
}
func updateFont(label: UILabel?) {
label?.font = label?.font.fontByUpdatingSize()
}
func updateButtonFont(button: UIButton?) {
button?.titleLabel?.font = button?.titleLabel?.font.fontByUpdatingSize()
}
func configureVideo(video: Video) {
if let attorney = video.attorney {
super.configure(attorney)
}
self.video = video
if let thumb = video.thumb {
self.picture?.loadImage(thumb, placeHolderName: "videoPlaceholder")
}
self.titleLabel?.text = self.video?.title
self.ageLabel?.text = self.video?.timespan
}
}