Swift 4 is a type-safe language which means if a part of your code expects a String, you can’t pass it an Int by mistake. As Swift 4 is type-safe, it performs type-checks when compiling your code and flags any mismatched types as errors.

import Cocoa

var myVar = 42
myVar = "This is a sample String"

Playground execution failed: error: :6:6: error: cannot assign to ‘let’ value ‘myVar’

myVar = “This is a sample String”

When we compile the above program, it produces the following compile time error.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.