Why am I getting a "Value of optional type UIFont not unwrapped", but unwrapping gives "unexpectedly found nil while unwrapping an optional"?

chris P
func initializePickerViewProperties() {
    let font = UIFont (name: "SanFranciscoDisplay-Regular", size: 30.0)
    let highlightedFont = UIFont (name: "SanFranciscoDisplay-Bold", size: 35.0)
    pickerView.font = font!
    pickerView.highlightedFont = highlightedFont!
}

fairly simple, the pickerView in question is an AKPickerView

If I remove the forced unwrapping I get a compiler error. "Value of optional type UIFont not unwrapped, did you mean to use "!" or "?"?"

However, when I force unwrap it, I get a runtime error. "fatal error: unexpectedly found nil while unwrapping an Optional value"

konrad.bajtyngier

Means your fonts are not initialized properly and give nil. You should safely unwrap them:

func initializePickerViewProperties() {
    if let font = UIFont (name: "SanFranciscoDisplay-Regular", size: 30.0),
        let highlightedFont = UIFont (name: "SanFranciscoDisplay-Bold", size: 35.0) {
        pickerView.font = font
        pickerView.highlightedFont = highlightedFont
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I keep getting this error "unexpectedly found nil while unwrapping an Optional value" Why?

From Dev

Getting unexpectedly found nil while unwrapping an Optional value

From Dev

When I try to save to ui colors with userDefaults, Xcode gives me the error : Fatal error: Unexpectedly found nil while unwrapping an Optional value

From Dev

bms-push cordova plugin on iOS gives: fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

SceneKit – Fatal Error: unexpectedly found nil while unwrapping an Optional value when getting child node

From Dev

SceneKit – Fatal Error: unexpectedly found nil while unwrapping an Optional value when getting child node

From Dev

Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value when getting Location?

From Dev

Swift - While playing sound I get error "fatal error: unexpectedly found nil while unwrapping an Optional value"

From Dev

When trying change url on button press I get the error : unexpectedly found nil while unwrapping an Optional value

From Dev

How can I fix "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" in Swift

From Dev

unexpectedly found nil while unwrapping an Optional

From Dev

Unexpectedly found nil while unwrapping optional value

From Dev

pickerView unexpectedly found nil while unwrapping an Optional

From Dev

Unexpectedly found nil while unwrapping an optional values

From Dev

Unexpectedly found nil while unwrapping an - Optional Value

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value. But I can't find nill value in my statement

From Dev

when coding, I get Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value any solutions

From Dev

unexpectedly found nil while unwrapping an Optional value : swift 2.1

From Dev

unexpectedly found nil while unwrapping an Optional value - Using ALAMOFIRE

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value swift

From Dev

Dictionary Unexpectedly found nil while unwrapping an Optional value

From Dev

Swift: UIImageView - Unexpectedly found nil while unwrapping an Optional value

From Java

Fatal error: unexpectedly found nil while unwrapping an Optional values

From Dev

Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

From Dev

Unexpectedly found nil while unwrapping an Optional value while opening UIViewController

From Dev

.reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

From Dev

Header Custom View: unexpectedly found nil while unwrapping an Optional value

Related Related

  1. 1

    I keep getting this error "unexpectedly found nil while unwrapping an Optional value" Why?

  2. 2

    Getting unexpectedly found nil while unwrapping an Optional value

  3. 3

    When I try to save to ui colors with userDefaults, Xcode gives me the error : Fatal error: Unexpectedly found nil while unwrapping an Optional value

  4. 4

    bms-push cordova plugin on iOS gives: fatal error: unexpectedly found nil while unwrapping an Optional value

  5. 5

    SceneKit – Fatal Error: unexpectedly found nil while unwrapping an Optional value when getting child node

  6. 6

    SceneKit – Fatal Error: unexpectedly found nil while unwrapping an Optional value when getting child node

  7. 7

    Getting nil values using NSDate (fatal error: unexpectedly found nil while unwrapping an Optional value)

  8. 8

    fatal error: unexpectedly found nil while unwrapping an Optional value when getting Location?

  9. 9

    Swift - While playing sound I get error "fatal error: unexpectedly found nil while unwrapping an Optional value"

  10. 10

    When trying change url on button press I get the error : unexpectedly found nil while unwrapping an Optional value

  11. 11

    How can I fix "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" in Swift

  12. 12

    unexpectedly found nil while unwrapping an Optional

  13. 13

    Unexpectedly found nil while unwrapping optional value

  14. 14

    pickerView unexpectedly found nil while unwrapping an Optional

  15. 15

    Unexpectedly found nil while unwrapping an optional values

  16. 16

    Unexpectedly found nil while unwrapping an - Optional Value

  17. 17

    fatal error: unexpectedly found nil while unwrapping an Optional value. But I can't find nill value in my statement

  18. 18

    when coding, I get Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value any solutions

  19. 19

    unexpectedly found nil while unwrapping an Optional value : swift 2.1

  20. 20

    unexpectedly found nil while unwrapping an Optional value - Using ALAMOFIRE

  21. 21

    fatal error: unexpectedly found nil while unwrapping an Optional value swift

  22. 22

    Dictionary Unexpectedly found nil while unwrapping an Optional value

  23. 23

    Swift: UIImageView - Unexpectedly found nil while unwrapping an Optional value

  24. 24

    Fatal error: unexpectedly found nil while unwrapping an Optional values

  25. 25

    Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  26. 26

    fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

  27. 27

    Unexpectedly found nil while unwrapping an Optional value while opening UIViewController

  28. 28

    .reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

  29. 29

    Header Custom View: unexpectedly found nil while unwrapping an Optional value

HotTag

Archive