Swift has the following code:
var videoBitrateLabel:UILabel={
let label: UILabel=UILabel()
label.textColor=UIColor.whiteColor()
return label}()
I will addSubview this instance later.
view.addSubview(videoBitrateLabel)
At a glance, I can understand that it is like this, but please tell me the meaning (effect?) of {} and ().
Also, how can I find out if I want to google it?
It will be the same as I wrote below.
Closure expression with no arguments, return value UILabel, and } after in.
You can omit ( ) - > UILabelin because of the type inference feature in swift.
Depending on the number of arguments and return values, you may not be able to omit them.
The last ( ) runs the closure formula.
var videoBitrateLabel:UILabel={()->UILabel in
let label: UILabel=UILabel()
label.textColor=UIColor.whiteColor()
return label
}()
© 2024 OneMinuteCode. All rights reserved.