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定义函数,在括号里定义參数和类型,用 ...
随机推荐
- 6.HBase In Action 第一章-HBase简介(1.2 HBase的使用场景和成功案例)
Sometimes the best way to understand a software product is to look at how it's used. The kinds of pr ...
- 微软发布独立Android模拟器 为开发者提供测试
微软发布了 Visual Studio 2015 正式版,除了免费的社交版之外,另外也有付费的专业版.这套工具除了提供 Windows 应用程序的整合环境之外,你也可以利用它来开发 Android 程 ...
- node的实践(项目二)
找以前看看简单的demo,看看node是怎么操作Mongo然后又是渲染前台的,与前面的项目一中的对比. 1.操作Mongo数据库的方法和方式. var mongodb = require('./db' ...
- 编写高质量代码改善C#程序的157个建议[为泛型指定初始值、使用委托声明、使用Lambda替代方法和匿名方法]
前言 泛型并不是C#语言一开始就带有的特性,而是在FCL2.0之后实现的新功能.基于泛型,我们得以将类型参数化,以便更大范围地进行代码复用.同时,它减少了泛型类及泛型方法中的转型,确保了类型安全.委托 ...
- 自动化测试UI Test, Performance Test, Load Test 总结整理
MSDN: 测试应用程序,Test apps early and often ,Improve Code Quality 推荐书: <Visual Studio 2015高级编程> < ...
- hdu1358 KMP
求循环节. #include<stdio.h> #include<string.h> #define maxn 1000010 int next[maxn]; char s[m ...
- Java设计模式-单例模式(Singleton)
单例对象(Singleton)是一种常用的设计模式.在Java应用中,单例对象能保证在一个JVM中,该对象只有一个实例存在.这样的模式有几个好处: 1.某些类创建比较频繁,对于一些大型的对象,这是一笔 ...
- 重启猫(modem)的方法
重启猫(modem)的方法 家里上网还是古老的"猫+路由器"模式,换路由器后就要reset猫,其步骤为: 断开猫电源 用针头或笔尖按住reset小孔,持续30秒 针抵住小孔的同时连 ...
- opencv笔记5:频域和空域的一点理解
time:2015年10月06日 星期二 12时14分51秒 # opencv笔记5:频域和空域的一点理解 空间域和频率域 傅立叶变换是f(t)乘以正弦项的展开,正弦项的频率由u(其实是miu)的值决 ...
- 【poj1804】 Brainman
http://poj.org/problem?id=1804 (题目链接) 题意 求逆序对 Solution1 归并排序. 每次合并时计算逆序对. 代码1 // poj1804 #include&l ...