Swift Tour 随笔总结 (1)
let Constant
var Variable
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
The so-called type implications
To include value in strings:
let fruitSummary = "I have \(apples + oranges) pieces of fruit."
Arrays and Dicts:
var shoppingList = ["catfish", "water", "tulips"]
shoppingList[1] = "bottle of water"
var occupations = [
"Malcolm": "Captain",
"Kaylee": "Mechanic",
]
occupations["Jayne"] = "Public Relations"
//empty
let emptyArray = String[]()
let emptyDictionary = Dictionary()
Control Flow and Optional Binding
For each
let individualScores = [75, 43 103, 87, 12]
var teamScore = 0
for score in individualScores {
if score > 50 {
teamScore += 3
} else {
teamScore += 1
}
}
teamScore
Optional Binding
var optionalString: String? = "Hello"
optionalString == nil
var optionalName:String? = "John Appleseed"
var greeting = "Hello!"
//optional binding
if let name = optionalName {
greeting = "Hello, \(name)"
}
If the optional value is nil, the conditional is false and the code in braces is skipped.
Otherwise, the optional value is unwrapped and assigned to the constant after let, which makes the unwrapped value available inside the block of code.
Swift Tour 随笔总结 (1)的更多相关文章
- Swift Tour 随笔总结 (4)
Switch的一个例子: let vegetable = "red pepper" switch vegetable { case "celery": let ...
- Swift Tour 随笔总结 (3)
关于Optional的Control Flow if let constantName = someOptional { statements } 如果该Optional为nil,则不进入if,否则执 ...
- Swift Tour 随笔总结 (2)
Type Aliases typealias AudioSample = UInt16 Booleans 非boolean值不会被替代为bool,例如: let i = 1 if i { // thi ...
- 【读书笔记】A Swift Tour
素材:A Swift Tour 推荐下载Playground:Download Playground objc 自己较为熟悉,想熟悉下风头正劲的 swift.就先从官方的入门手册开始撸. 每一小节,我 ...
- [IOS]《A Swift Tour》翻译(一)
以下翻译内容为原创,转载请注明: 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3768936.html 碎碎念... Swift是苹果在WWDC刚发 ...
- Swift tour
输出函数: print(“hello world!") 无需引入函数库,无须使用“;”作为语句结尾,也无须写跟其它语言一样的main()函数,Swift中,全局区的代码就是程序入口.You ...
- A Swift Tour(3) - Functions and Closures
Functions and Closures 使用func来声明函数,通过括号参数列表的方式来调用函数,用 --> 来分割函数的返回类型,参数名和类型,例如: func greet(name: ...
- A swift Tour
传统的认为,一个新的语言的第一个应用程序都会打印"Hellow,Word",在Swift中,可以只需要一行代码: pringln("Hello, word") ...
- Swift学习——A Swift Tour 函数
Functions and Closures 函数和封闭性(闭包) Functions 函数的使用 Swift中的函数定义和OC中有明显的差别了,使用func定义函数,在括号里定义參数和类型,用 ...
随机推荐
- html5新增选择器
分享点html5的学习笔记,比较基础,突然发现通过写博客来记笔记有很多优点呢,平常记得笔记比较简单,复习起来比较吃力,看自己的博客理解起来还比较轻松,而且只有真正理解了才能表达清楚让别人看懂,还锻炼语 ...
- css基本的东西
0 css本来也是一个比较乱的东西,我们需要在最恰当的情况下,写出最杂乱的效果.1 面对body设置了 -webkit-font-smoothing:antialiased (默认值为subpixel ...
- [AHOI2013]打地鼠(网络流)
[问题描述] 游戏里一共会冒出来N个地鼠,这些地鼠冒出来的位置都分布在一条直线上.第i个地鼠会在Ti时刻在Xi位置冒出来,打到第i个地鼠的得分是Pi. 当游戏开始时(也就是0时刻) ...
- http加速软件使用说明
HTTP加速软件使用说明 http加速软件使用于卫星链路,在卫星链路时延高的情况下提高http的传输速率 1.1 软件包依赖 (1)squid-3.4.5.tar.gz (2)trafficserve ...
- 这些天自身努力的体会,关于java方面的
以前也是接触过java,这学期的软件工程课和周围同学各种比赛取得不错的成绩,确实令人倍感压力.为此这几天使劲脑补了一下java的知识,甚至不惜为此翘课,了解了java中的网络编程,对于sokectse ...
- WCF学习(二)对控件简单了解以及4个文本控件的简介
WPF基础控件 系统默认提供的基础控件: 文本控件介绍与用法 Label控件 label控件:一般用户描述性文字显示. 在Label控件使用时,一般给予用户提示.用法上没有什么很特殊的,label控件 ...
- hdu3613 扩展KMP
#include<stdio.h> #include<string.h> #define maxn 501000 char s[maxn],t[maxn]; int next[ ...
- hdu1828 线段树+离散化+扫描线
添加lb[],rb[]数组,来标记竖边.添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加. #include<stdio.h> #include<stdlib.h ...
- BZOJ-2242 计算器 快速幂+拓展欧几里得+BSGS(数论三合一)
污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][S ...
- Android APK反编译问题
因为这几天想做一个离线音乐播放器,然后需要很多.png图片,在度娘上搜图片感觉效果不好, 就需要用到反编译工具来将一些.apk文件中的资源文件提取出来. 这里就只讲下怎么使用工具来进行反编译,什么?你 ...