Chathuranga Silva Chathuranga Silva - 1 year ago 128
iOS Question

UIFont is not convertible error

I just converted my swift 2.3 code to 3.0,But suddenly UILabel view shows an error when I try to change the font type. Here is the error. It shows that

(name: String, size: CGFloat)-> UIFont is not convertible to (name: String, size: CGFloat)-> UIFont?
why can't I change Font type ? I've cleaned and built the project but show same error. Here is the UILabel

let placeholder = UILabel()
placeholder.bounds = self.tableView.bounds
placeholder.textAlignment = .Center
placeholder.textColor = UIColor(red: 230.0/255.0, green: 230.0/255.0, blue: 230.0/255.0, alpha: 1.0)
placeholder.font = UIFont(name: "Avenir-Light", size: 15.0)
placeholder.text = "No Events"
self.tableView.backgroundView = placeholder

Here is the error

enter image description here

Answer Source
placeholder.font = UIFont(name: "Avenir-Light", size: 15.0)

you should try writing this:

placeholder.font = UIFont.init(name: "Avenir-Light", size: 15)

for more information see this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download