How to resolve “Initializer for conditional binding must have Optional type, not 'Int'”?

前端 未结 1 1346
名媛妹妹
名媛妹妹 2021-01-17 03:49

I\'ve seen examples of how to resolve this error but I can\'t get it to work in my case.

Initializer for conditional binding must have Optional type,

1条回答
  •  天涯浪人
    2021-01-17 04:36

    The problem is UserDefaults.standard.integer return Int, not Int?. So you don't need to wrap it with if let.

    The optional is irrelevant whether on right side.

    In your case, just return UserDefaults.standard.integer(forKey: "employeeCount")

    0 讨论(0)
提交回复
热议问题