How to ensure make sure I´m not accessing data until it´s loaded in?

前端 未结 1 1003
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 06:25

I´m new at programming and I my code gets the error: fatal error: unexpectedly found nil while unwrapping an Optional value 2017-10-27 16:06:16.755817+0200 Inspireme1.0[836:8530

相关标签:
1条回答
  • 2021-01-29 06:48

    Quotes should not be optional.

    You need to handle the optional outcome in viewDidAppear rather than assuming quotes will always unwrap.

    quotes = defaults.codable(RandomItems.self, forKey: "quotes") ?? RandomItems([])

    In viewDidLoad:

    defaults.set(codable: quotes, forKey: "quotes")
    
    0 讨论(0)
提交回复
热议问题