× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Lazy readonly property in swift

Antonio Bello
Mar 01, 2015
<p>If readonly and private are synonyms for you in this specific case, then you can make the setter private by explicitly declaring it:</p> <pre><code>private(set) lazy var foo : Int = { return 42 }() </code></pre> <p>That's a good compromise between immutability and laziness.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26048138/Lazy%20readonly%20property%20in%20swift/26048425">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus