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
Updated 28 February 2022
In this blog, we will see Object-Oriented programming in swift. It is a programming paradigm that is based on the concept of objects. Let’s start with classes.
Class is a blueprint from which an object is created. To declare a class we use the class keyword.
In the above example, we have created a class Bird, which has properties legs, feathers. All the birds have different characteristics, but they share some common properties such as legs, feathers.
An example of class In swift is UIView.
It is the implementation of the class which can access any methods and properties of a class. We can create multiple objects of the same class but class declared only once.
An example of objects in swift is that when we create the outlet of UICollectionView then we create an object of it.
In the above example legs, the feather is the property of Birds. In swift point of view isEnabled, textColor is the properties.
Methods are the behavior. In the below example canFly is a method that indicates the behavior of the birds.
It is the binding of the data member and member methods in a single unit. We can achieve encapsulation by Access control.
Abstraction is hidding the implementation and only showing the relevant data and method of the object. In the above example if someone wants to see the parrot fly then he is simply interested in seeing the parrot fly but not interested in how it is actually flying. Therefore, in the above scenario, only canFly() method needs to call.
It means more than one form of the same type. In the above example, we created a method canFly(), which means birds can fly but there is some exception for birds that can’t fly.
The example which we mentioned above has object of Kiwi, and as it is a bird but it can’t fly so we have use the override keyword to override the method canFly and thus we achieve Method Overriding.
In swift when creating any ViewController and since it is a subclass of UIViewController so we override its method viewDidLoad(). In the Kiwi example if we declare two methods with the same name but different parameters then it will be Method Overlodaing.
Ihneritance is the process of accuring the properties of the parent class into the child class. As we can see kiwi is inheritated from the bird. So it can access the properties of birds
In swift as the label is child class of UIView, so it can access its properties isHidden.
Swift provide four level of Access control
Thanks for reading this blog.
You can also check other blogs from here. If you have any issues, queries, or suggestions then you can leave your issues/query/suggestion in the comment section.
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.