[SOLVED] How to return struct in swift?

Issue

This is my struct:

struct State {
  var current: StateEntry?
  var rStack: [StateEntry] = []
  var uStack: [StateEntry] = []
}

and i have a func that has return type State:

func createEmptyState() -> State {
  var state = State.self
  return  state.current == nil, state.rStack == [], state.uStack == []//How do I return these values of struct in this function?
}

Solution

To return null object

return State()

To return object containing something.

return State(current: StateEntry(), rStack: [], uStack: [])

Answered By – Hashim Khan

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published.