Polymorphism is a concept in object-oriented
programming where objects of different classes can be 
treated as if they are the same type. In Swift,
this means that objects that conform to the same 
protocol can be used interchangeably, even though 
they are of different types.

For example, let's say we have two classes, 
Rectangle and Circle, which both conform to a
Shape protocol. We can create an array of Shape 
objects and add instances of Rectangle and Circle to it.
Then we can loop through the array and call the same 
method on each object, even though they are of different types. 
This is because they all conform to the Shape protocol and 
implement the required methods.

Polymorphism allows for greater flexibility 
and reuse of code, as we can write methods that 
work on multiple types of objects without needing 
to know their specific class. It also makes it easier 
to write generic code that can work with any type that 
conforms to a certain protocol, rather than needing to
write separate code for each specific type.




see this: https://www.cosmiclearn.com/swift/polymorphism.php  Definition of Polymorphism:
  Poly means many and Morphism means form. 
  Polymorphism is when a class or function 
  is used in different places with the same name.

  Polymorphism can be done in two ways –
  1st: When the same function of a class is 
  used repeatedly with the same name in different 
  ways, it is called polymorphism. This process is
  also called overloading.

  2nd: When a class is inherited by another class 
  with the same name and used in different ways, 
  it is called polymorphism. This process is also 
  called overriding.

/// Bangla Explain: 
  পলিমরফিজম এর সংজ্ঞা: 
  Poly মানে হলো বিভিন্ন বা অনেক বা বহু, আর Morphism মানে হলো রূপ। 
	কোনো ক্লাসকে বা ফাঙ্কশনকে একই নামে অন্য জায়গায় বিভিন্নরূপে ব্যবহার করা 
	হলে তাকে পলিমরফিজম বলে। 

  পলিমরফিজম দুইভাবে করা যায় - 
  ১ম : কোনো ক্লাসের একই ফাঙ্কশন বার বার একই নামে বিভিন্নরূপে ব্যবহার 
	করা হলে তাকে পলিমরফিজম বলে। এই প্রক্রিয়াটাকে ওভারলোডিংও বলে।  

  ২য় : কোনো ক্লাসকে একই নামে অন্য কোনো ক্লাসে ইনহেরিট করে বিভিন্ন অর্থে 
	ব্যবহার করা হলে তাকে পলিমরফিজম বলে। এই প্রক্রিয়াটাকে ওভাররাইডিংও বলে।  

  এবার চলুন আমরা সুইফ্টে পলিমরফিজমের উদাহরণ হিসাবে দেখে আসি  -> 

  Now let's look at as an example of polymorphism in Swift ->



// 1st:
  //  MARK: Definition of Polymorphism ->
/// Method Overloading Polymorphism ->
class OverLoad {

   public func student_Information(name: String) -> String {
        return "Name \(name)."
    }

    func student_Information(name: String, id: Int) -> String {
        return "Name: \(name). ID: \(id)."
    }

    func student_Information(name: String, id: Int, address: String) -> String {
        return "Name: \(name), ID: \(id), Address: \(address)."
    }
}

let st_I = OverLoad()
print(st_I.student_Information(name: "MD Murad Hossain"))
print(st_I.student_Information(name: "MD Faysal Ahmed", id: 124554))
print(st_I.student_Information(name: "MD Abul Kasehem", id: 343243, address: "Chadpur, Chittagong"))

// 2nd: 
// MARK: Methode Overriding Polymorphism ->

class Person {
    public func man() {
        print("Hi!, I'm a person.")
    }
}

class Student: Person {
    public override func man() {
        print("Hi!, I'm a student.")
    }
}

class Teacher: Person {
    public override func man() {
        print("Hi!, I'm a teacher.")
    }
}

let p = Person()
let s = Student()
let t = Teacher()
p.man()
s.man()
t.man()

Swift相关代码片段

close avplayer at end swift

create a clickable button in swiftui

videoplayer swiftui loop

horizontal scrollview from right to left swiftui

model in swift

using c++ in swift

make a horizontal scrollview snappy swiftui

method overriding in swift

weekofmonth start with sunday swiftui

api data call in swift

cameraDeviceSet

how to force view orientation in swiftui

swiftui symbol render mode

localize string in swift model

keyboard covers textinput swiftui

fixed decimal digits swiftui

swift switch multiple case

scroll view adjust on keyboard appearing

Adjust Scroll view on keyboard appearing swift

fix xcode indent

annotation only added to last item swiftui charts

add scroll charts swiftui

taylor swift nfl

datepicker swift limit possible days

auto width zstack roundedrectangle swift

image cover over safe area view swiftui

change color swift chart

generate date without hour swift

cut string swift

control fill opacity swiftui

convert ckasset to uiimage

Date formatted swift

menu list popup in swift

multiple present viewcontroller dismiss in swift

select image and store in cloudkit swift

add image selector swiftui

swift comment mark

stepper with manual input swiftui

NumberFormatter double swiftui

number float picker swiftui

horizontal picker swiftui

pass function swiftui view

label change text color swiftui

longpress action opens menu swiftui

check if two dates are the same day swift

get current month number int swiftui

foregroundcolor auto color swiftui

system gray swiftui

capsule auto with content swiftui

sort array of objects by date swift

convert datecomponents to date swift

get first day of certain month and year swiftui

foreach get index value swiftui

get current month year swiftui

swiftui datepicker only month and year

custom font programmatically in swift

generate array of years in string format swiftui

remove whitespace string swift

clear dictionary swiftui

toolbarBackground doesn't work swiftui ios17

check if app is running on ipadOs swiftui

lazyvstack dynamic columns ipados swiftui

swift perform selector

swift logger

throw exception swift

color picker swiftui

custom sheet size swiftui

date picker without time swiftui

numeric field swiftui

circular rectangle shape swiftui

datepickerdialog swift

delete item dictionary swift

delete cloudkit record

calculate the day 7 days ago swiftui

generate new date from string swiftui

convert fetchedresults type to another array

swift mailer

corner radius swift ui ios 17

list swipe actions swiftui

generate todays date 1h less swiftui