Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why an Int32 variable can't be assigned to an Int64 variable or vice versa in Swift?

I could not assign Int32 var/let to Int64 var/let or vice-versa in Swift. I get a compile time error when I attempt to do so. What is the reason behind this ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you declare a variable as Int32, the memory allocated for that variable is 4bytes and for Int64 type variable the memory allocated is 8 bytes.

You can’t put 64bytes data into 32 byte data as you can’t put 2litres of water into 1 litre bottle.

In order to avoid such problems, swift has strict type checking feature and ensure such problems are not arise in run time.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading