[swift-users] Stored Property, Externally Read-Only
Bob Davidson
thegreatvoid at gmail.com
Fri Apr 29 12:27:17 CDT 2016
Great, thanks guys
On Fri, Apr 29, 2016 at 12:00 PM Nate Birkholz <nbirkholz at gmail.com> wrote:
> That's correct.
>
> On Fri, Apr 29, 2016 at 8:52 AM, David Sweeris via swift-users <
> swift-users at swift.org> wrote:
>
>> Yep, declare it like this:
>> public private(set) var lastUpdated: NSDate?
>>
>> At least I’m pretty sure that’s the syntax. I don’t have Xcode in front
>> of me to double-check.
>>
>> HTH
>> - Dave Sweeris
>>
>> On Apr 29, 2016, at 9:52 AM, Bob Davidson via swift-users <
>> swift-users at swift.org> wrote:
>>
>> Hello,
>>
>> Does Swift have a syntax for allowing a stored property to be internally
>> changed by a class/structure, but external access is read-only?
>>
>> For example, my class/structure may have a date property such as
>> “lastUpdated”. Outside code should have access to read the “lastUpdated”
>> property, but should not be allowed to change it. Periodically, my class
>> may perform an “update” and would internally change the value of
>> “lastUpdated”.
>>
>> The only way I see to support this with a private property and a
>> computed, get-only property:
>>
>> private var internalLastUpdated: NSDate?
>> var lastUpdated: NSDate? { return internalLastUpdated }
>>
>> This there a better way?
>>
>> Thanks,
>> Bob Davidson
>>
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>>
>>
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>>
>
>
> --
> Nate Birkholz
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160429/46b21545/attachment.html>
More information about the swift-users
mailing list