<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Yep, declare it like this:<div class=""><div dir="ltr" class=""><span class=""><div class="" style="font-family: HelveticaNeue;"><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>public private(set)&nbsp;var lastUpdated: NSDate?</div><div class=""><br class=""></div><div class="">At least I’m pretty sure that’s the syntax. I don’t have Xcode in front of me to double-check.</div><div class=""><br class=""></div><div class="">HTH</div><div class="">- Dave Sweeris</div></div></span></div><div class=""><div dir="ltr" class=""><span class=""><div class="" style="font-family: HelveticaNeue;"><div class=""><br class=""></div></div></span></div></div><div><blockquote type="cite" class=""><div class="">On Apr 29, 2016, at 9:52 AM, Bob Davidson via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span class=""><div style="font-family: HelveticaNeue; font-size: 12px;" class="">Hello,<div class=""><br class=""></div><div class="">Does Swift have a syntax for allowing a stored property to be internally changed by a class/structure, but external access is read-only?</div></div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><br class=""></div><div style="font-family: HelveticaNeue; font-size: 12px;" class="">For example, my class/structure may have a date property such as “lastUpdated”.&nbsp; Outside code should have access to read the “lastUpdated” property, but should not be allowed to change it.&nbsp; Periodically, my class may perform an “update” and would internally change the value of “lastUpdated”.</div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><br class=""></div><div style="font-family: HelveticaNeue; font-size: 12px;" class="">The only way I see to support this with a private property and a computed, get-only&nbsp;property:</div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><br class=""></div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>private var internalLastUpdated: NSDate?</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var lastUpdated: NSDate? { return internalLastUpdated }</div></div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><br class=""></div><div style="font-family: HelveticaNeue; font-size: 12px;" class="">This there a better way?</div><div style="font-family: HelveticaNeue; font-size: 12px;" class=""><br class=""></div><div style="font-family: HelveticaNeue; font-size: 12px;" class="">Thanks,</div><div style="font-family: HelveticaNeue; font-size: 12px;" class="">Bob Davidson</div></span><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>