[SOLVED] How to return struct in swift?


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?


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. Required fields are marked *