Downcasting in Swift with as and as?

后端 未结 3 552
我在风中等你
我在风中等你 2020-12-16 13:48

What\'s the difference between these two code snippets:

let cell = tableView.dequeueReusableCellWithIdentifier(\"cellId\") as UITableViewCell?
// vs
let cell         


        
3条回答
  •  别那么骄傲
    2020-12-16 14:49

    The difference between, as and as?

    • as? UITableViewCell means when you don't know what you're downcasting, you are assuming that as a UITableViewCell, but it might me Integer or Float or Array or Dictionary.

    • as UITableViewCell? means it's an Optional Value, it may either contain a UITableViewCell or Nil value.

提交回复
热议问题