Abstract
You can observe the state of a property with the willSet and didSet keywords. You can use these in the property declaration to assign an action that will occur when a property is about to change and when a property value just changed. Listing 35-1 shows how you would add an action that prints a message to the console log whenever the age property value is about to change and after the age value has changed.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2014 Matthew Campbell
About this chapter
Cite this chapter
Campbell, M. (2014). Property Observers. In: Swift Quick Syntax Reference. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0439-9_35
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0439-9_35
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0440-5
Online ISBN: 978-1-4842-0439-9
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)