Swift 备忘单和快速参考
var myInt =
var myExplicitInt: Int = // explicit type
var x = , y = , z = // declare multiple integers
myExplicitInt = // set to another integer value
Constants
let myInt =
myInt = // compile-time error!
Strings
var myString = "a"
let myImmutableString = "c"
myString += "b" // ab
myString = myString + myImmutableString // abc
myImmutableString += "d" // compile-time error! let count =
let message = "There are \(count) days in a week"
Logical Operators
var happy = true
var sad = !happy // logical NOT, sad = false
var everyoneHappy = happy && sad // logical AND, everyoneHappy = false
var someoneHappy = happy || sad // logical OR, someoneHappy = true
Printing
let name = "swift"
println("Hello")
println("My name is \(name)")
print("See you ")
print("later")
/* Hello
My name is swift
See you later */
Arrays
var colors = ["red", "blue"]
var moreColors: String[] = ["orange", "purple"] // explicit type
colors.append("green") // [red, blue, green]
colors += "yellow" // [red, blue, green, yellow]
colors += moreColors // [red, blue, green, yellow, orange, purple] var days = ["mon", "thu"]
var firstDay = days[] // mon
days.insert("tue", atIndex: ) // [mon, tue, thu]
days[] = "wed" // [mon, tue, wed]
days.removeAtIndex() // [tue, wed]
Dictionaries
var days = ["mon": "monday", "tue": "tuseday"]
days["tue"] = "tuesday" // change the value for key "tue"
days["wed"] = "wednesday" // add a new key/value pair var moreDays: Dictionary = ["thu": "thursday", "fri": "friday"]
moreDays["thu"] = nil // remove thu from the dictionary
moreDays.removeValueForKey("fri") // remove fri from the dictionary
Conditionals
//IF STATEMENT
let happy = true
if happy {
println("We're Happy!")
} else {
println("We're Sad :('")
}
// We're Happy! let speed =
if speed <= {
println("Stationary")
} else if speed <= {
println("Safe speed")
} else {
println("Too fast!")
}
// Safe speed //SWITCH STATEMENT
let n =
switch n {
case :
println("It's 1!")
case ...:
println("It's between 2 and 4!")
case , :
println("It's 5 or 6")
default:
println("Its another number!")
}
// It's between 2 and 4!
For Loops
for var index = ; index < ; ++index {
// loops with index taking values 1,2
}
for index in .. {
// loops with index taking values 1,2
}
for index in ... {
// loops with index taking values 1,2,3
}
let colors = ["red", "blue", "yellow"]
for color in colors {
println("Color: \(color)")
}
// Color: red
// Color: blue
// Color: yellow
let days = ["mon": "monday", "tue": "tuesday"]
for (shortDay, longDay) in days {
println("\(shortDay) is short for \(longDay)")
}
// mon is short for monday
// tue is short for tuesday
While Loops
var count =
while count < {
println("count is \(count)")
++count
}
// count is 1
// count is 2 count =
while count < {
println("count is \(count)")
++count
}
// count =
do {
println("count is \(count)")
++count
} while count <
// count is 1
// count is 2 count =
do {
println("count is \(count)")
++count
} while count <
// count is 1

Swift 备忘单和快速参考的更多相关文章
- Nmap备忘单:从探索到漏洞利用(Part 2)
这是我们的第二期NMAP备忘单(第一期在此).基本上,我们将讨论一些高级NMAP扫描的技术,我们将进行一个中间人攻击(MITM).现在,游戏开始了. TCP SYN扫描 SYN扫描是默认的且最流行的扫 ...
- Objective-C教程备忘单
终极版本的Objective-C教程备忘单帮助你进行iOS开发. 想开始创建你的第一个iOS应用程序么?那么看一下这篇很棒的教程吧:Create your first iOS 7 Hello Worl ...
- Cheat (tldr, bropages) - Unix命令用法备忘单
cheat 是一个Unix命令行小工具,用来查询一些常用命令的惯用法(我们都知道,man page阅读起来太累了,常常是跳到最后去看 examples,但并不是所有man pages里面都有examp ...
- Nmap备忘单:从探索到漏洞利用(Part 5)
这是备忘单的最后一部分,在这里主要讲述漏洞评估和渗透测试. 数据库审计 列出数据库名称 nmap -sV --script=mysql-databases 192.168.195.130 上图并没有显 ...
- Nmap备忘单:从探索到漏洞利用(Part 4)
这是我们的Nmap备忘单的第四部分(Part 1. Part 2. Part 3).本文中我们将讨论更多东西关于扫描防火墙,IDS / IPS 逃逸,Web服务器渗透测试等.在此之前,我们应该了解一下 ...
- HTML5属性备忘单
在网上闲逛的时候看到了文章,感觉总结的这个html5文章,决定转载过来,在排版的时候也帮助自己重新梳理复习一遍.毕竟学习基础最重要. by zhangxinxu from http://www.zha ...
- Nmap备忘单:从探索到漏洞利用(Part3)
众所周知NMAP是经常用来进行端口发现.端口识别.除此之外我们还可以通过NMAP的NSE脚本做很多事情,比如邮件指纹识别,检索WHOIS记录,使用UDP服务等. 发现地理位置 Gorjan Petro ...
- OWASP WEB会话管理备忘单 阅读笔记
https://www.owasp.org/index.php/Session_Management_Cheat_Sheet#Session_ID_Properties 会话简介 HTTP是一种无状态 ...
- Nmap备忘单:从探索到漏洞利用 Part1
在侦查过程中,信息收集的初始阶段是扫描. 侦查是什么? 侦查是尽可能多的收集目标网络的信息.从黑客的角度来看,信息收集对攻击非常有帮助,一般来说可以收集到以下信息: 电子邮件.端口号.操作系统.运行的 ...
随机推荐
- P2特征(一)
很多人在提到项目的特征,肯定能说出来很多的内容,但是在英国体系下,项目的特点有哪些呢?这些特点引深的内容又有什么深度的含义. 项目具有临时性:很多人都知道项目是临时的,结束了就团队成员 ...
- jQuery中的100个技巧
1.当document文档就绪时执行JavaScript代码. 我们为什么使用jQuery库呢?原因之一就在于我们可以使jQuery代码在各种不同的浏览器和存在bug的浏览器上完美运行. < ...
- 冰冻三尺非一日之寒--web框架Django(翻页、cookie)
第二十一章 cookie 1.获取Cookie: request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR, ...
- Masonry tableviewCell布局(转)
转载自:http://www.henishuo.com/masonry-tableviewcell-layout/ 前言 说到iOS自动布局,有很多的解决办法.有的人使用xib/storyboard自 ...
- 文本文件关键字替换(Java)
代码实现如下: import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class File ...
- Oracle 性能优化
(1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table) ...
- html页面制作css基本设置
html{ height: 100%;} *{ margin: 0; padding: 0;}/* tell the browser to render HTML 5 elements as bloc ...
- Web API系列(二)接口安全和参数校验
以前简单介绍过web api 的设计,但是还是有很多朋友问我,如何合理的设计和实现web api.比如,接口安全,异常处理,统一数据返回等问题.所以有必要系统的总结总结 web api 的设计和实现. ...
- 解决Myeclipse PermGen space问题
myeclipse配置web服务器配置 Window—Preferences—Myeclipse—Servers—tomcat JDK的Optional Java VM arguments配置为:-X ...
- Android开发加快sdk更新速度
1.在:\Windows\System32\drivers\etc目录下找到host文件,不能再这个目录修改host文件,需要先拷贝到桌面 然后把一下地址添加到host文件的最末尾 203.208.4 ...