Type safety and type inference

Swift is a type-safe language, which means that you are encouraged to be clear about the types of values with which your code will work. Type inference means that before your code runs, it will be able to quickly check to ensure that you did not set anything to a different type. If you do, Xcode will give you an error. Why is this good? Let's say that you have an app in the store, and you set one of your variables as a String in one part of your code, but then accidentally set the same variable as an Int in another part of your code. This error may cause some bad behavior in your app that could cause it to crash. Finding these kind of errors is like finding a needle in a haystack. Therefore, type checking helps you ...

Get iOS 10 Programming for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.