官术网_书友最值得收藏!

Type safety and type inference

Swift is a type-safe language, which means that you are encouraged to be clear about the value types with which your code works. Type inference means that, before your code runs, it quickly checks to ensure that you did not set anything to a different type. If you do, Xcode gives you an error. Why is this good? Let's say that you have an app in the store and that 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 kinds of errors is like finding a needle in a haystack. Therefore, type checking helps you write safer code by helping you to avoid errors when working with different types.

We have now looked at data types and know that strings are for textual data, Int is for integer, Bool is for Boolean, and Double and Float are for floating-point numbers. Let's look a bit deeper into data types and see how we can do more than assign them to variables.

主站蜘蛛池模板: 常熟市| 保亭| 横峰县| 旬阳县| 来安县| 山东省| 正镶白旗| 新巴尔虎左旗| 健康| 南陵县| 腾冲县| 晋城| 班玛县| 垣曲县| 蕉岭县| 延长县| 大石桥市| 淮滨县| 横山县| 亳州市| 平度市| 木兰县| 彩票| 桃江县| 洪雅县| 临西县| 吉水县| 西盟| 高碑店市| 阜南县| 汶上县| 阿鲁科尔沁旗| 彭阳县| 祁东县| 吉水县| 双柏县| 汕尾市| 晴隆县| 镇平县| 九台市| 黄陵县|