[swift-users] Re-initializing lazy vars

Joanna Carter joanna at carterconsulting.org.uk
Sat Oct 21 04:33:00 CDT 2017


Oops! forgot to add example code for resetting with non-optional public var :

public struct TestStruct
{
  private var _description: String?
  
  public var description: String
  {
    get
    {
      return _description ?? ""
    }
    set
    {
      _description = newValue
    }
  }
  
  mutating func resetDescription()
  {
    _description = nil
  }
}

Joanna

--
Joanna Carter
Carter Consulting



More information about the swift-users mailing list