Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Hello, In this blog we are going to learn about reflection in swift. Reflection in swift uses Mirror API to inspect and manipulate properties at runtime. Its functionality in swift is more limited in comparison to other programming languages.
Mirror API contains a few properties via which we can access the properties of a type. Below is the example of Reflection in Swift.
In the above example, you can see that we have created an object of structure type and passed it to the Mirror API. Then in the next line, we are using children property to fetch all the properties of the structure A and printing them. The children property returns an array of tuple which contains 2 values. The first is label which is of optional String type and returns the name of the property and the second is value which is Any type and returns the value of the property.
structure
Mirror
children
tuple
label
value
Any
The mirror API contains a few more properties which are explained below.
superclassMirror
displayStyle
DisplayStatus
class
enum
optional
collection
subjectType
The mirror API works same with class type objects. Below is an example illustrating this.
Thank you for reading this article. After that, if you want to read more articles regarding iOS DevelopmentĀ click here or if you want to read more about Mirror API click here.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.