The iOS Apprentice1-10 计算分数

2016-04-28  本文已影响0人  花开花落花满天

本章中,主要涉及if 判断语句,var / let 区别,以及之前内容回顾(label的更新)

1. 计算currentValue和targetValue的差值

var  difValue = currentValue - targetValue
if difValue < 0{
    difValue = difValue * (-1)
  }

*注意上述difValue的定义方式,没有定义其数据类型。swift能够更加currentValue 和 targetValue的数据类型去推断difValue数据类型

This feature is called type inference(类型推断) and it's one of the big selling points of Swift.

注意上述定义使用的是let ,而之前使用的是var,两者之间有什么区别。let定义的是一个常量,而var定义的是一个变量。
The keyword var creates a variable while let creates a constant. That means difference is now a constant, not a variable.

2.添加总分和游戏轮数

上一篇 下一篇

猜你喜欢

热点阅读