<div dir="ltr"><div>One of the aspects of Swift that I like is computed properties for structures and classes. It allows for adding logic when obtaining values or for having the returned value be dependent on another.</div><div><br></div><div>As of the `ErrorType` protocol introduction in Swift 2, we can throw errors when it comes to functions and initializers. However, this does not apply to getters and setters.</div><div><div><div><br></div><div><div>```swift</div><div>struct File&lt;Data&gt; {</div><div>    var contents: Data {</div><div>        get throws { ... }</div><div>        set throws { ... }</div><div>    }</div><div>}</div><div>```</div></div></div><div><br></div><div>A better example would be getting and setting the current working directory of the process:</div><div><br></div><div><div>```swift</div><div>import Foundation</div><div><br></div><div>extension Process {</div><div>    static var workingDirectory: String {</div><div>        get {</div><div>            let fileManager = NSFileManager.defaultManager()</div><div>            return fileManager.currentDirectoryPath</div><div>        }</div><div>        set throws {</div><div>            let fileManager = NSFileManager.defaultManager()</div><div>            guard fileManager.changeCurrentDirectoryPath(newValue) else {</div><div>                throw Error(&quot;...&quot;)</div><div>            }</div><div>        }</div><div>    }</div><div>}</div><div><br></div><div><br></div><div><br></div><div>```</div></div><div><br></div><div><br></div></div></div>