shle2821 shle2821 - 1 year ago 67
Swift Question

In Swift, can you pass nil as an input to a function?

I'm reading many articles about how you shouldn't check an object for nil. It's a objC paradigm and it's a bad design and w/ swift it's been eliminated. So my question is, per example below, can you pass thru "group" as nil value? does the nil-checking mechanism happen when the function is called, hence removing the need to implement if(group==nil){..} ?

func deleteMembershipForGroup(group:GroupData){

Answer Source

You need to use an optional:

func deleteMembershipForGroup(group:GroupData?){
  if let groupReal = group {
  // not nil