thii / FontAwesome.swift

Use FontAwesome in your Swift projects
MIT License
1.57k stars 265 forks source link

Nil fontName leads to crash #279

Closed Rspoon3 closed 2 years ago

Rspoon3 commented 2 years ago

Running the basic example from the README causes a crash.

System Info:

Reproduction steps:

  1. Create a new Xcode project
  2. Add FontAwesome via Swift Package Manager
  3. Copy and paste the code below
  4. Run the application
import UIKit
import FontAwesome

class ViewController: UIViewController {
    let imageView = UIImageView()

    override func viewDidLoad() {
        super.viewDidLoad()

        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.image = UIImage.fontAwesomeIcon(name: .github,
                                                  style: .regular,
                                                  textColor: .systemPurple,
                                                  size: .init(width: 300, height: 300))

        view.addSubview(imageView)

        NSLayoutConstraint.activate([
            imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            imageView.widthAnchor.constraint(equalToConstant: 400),
            imageView.heightAnchor.constraint(equalToConstant: 400),
        ])
    }
}

Actual Results: A crash occurs due to the fontName being nil Screen Shot 2022-04-18 at 11 12 51 PM

Expected Results: An image should render

Rspoon3 commented 2 years ago

Duplicate of https://github.com/thii/FontAwesome.swift/issues/236