ios Swift 备忘录
Variables
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
Functions
func iAdd(a: Int, b: Int) -> Int {
return a + b
}
iAdd(, ) // returns 5 func eitherSide(n: Int) -> (nMinusOne: Int, nPlusOne: Int) {
return (n-, n+)
}
eitherSide() // returns the tuple (4,6)
Classes
class Counter {
var count: Int =
func inc() {
count++
}
func add(n: Int) {
count += n
}
func printCount() {
println("Count: \(count)")
}
} var myCount = Counter()
myCount.inc()
myCount.add()
myCount.printCount() // Count: 3
ios Swift 备忘录的更多相关文章
- Swift备忘录
Swift 备忘录 2015-4 一.简介 1.Swift 语言由苹果公司在2010年7月开始设计,在 2014 年6月推出,在 2015 年 12 月 3 日开源 2.特点(官方): (1)苹果宣称 ...
- iOS swift的xcworkspace多项目管理(架构思想)
iOS swift的xcworkspace多项目管理(架构思想) 技术说明: 今天在这里分享 swift下的 xcworkspace多项目管理(架构思想),能为我们在开发中带来哪些便捷?能为我们对整 ...
- iOS Swift 模块练习/swift基础学习
SWIFT项目练习 SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图 +控件 1.UIImag ...
- ios swift 实现饼状图进度条,swift环形进度条
ios swift 实现饼状图进度条 // // ProgressControl.swift // L02MyProgressControl // // Created by plter on 7/2 ...
- Building gRPC Client iOS Swift Note Taking App
gRPC is an universal remote procedure call framework developed by Google that has been gaining inter ...
- iOS Swift WisdomScanKit图片浏览器功能SDK
iOS Swift WisdomScanKit图片浏览器功能SDK使用 一:简介 WisdomScanKit 由 Swift4.2版编写,完全兼容OC项目调用. WisdomScanKit的 ...
- iOS Swift WisdomScanKit二维码扫码SDK,自定义全屏拍照SDK,系统相册图片浏览,编辑SDK
iOS Swift WisdomScanKit 是一款强大的集二维码扫码,自定义全屏拍照,系统相册图片编辑多选和系统相册图片浏览功能于一身的 Framework SDK [1]前言: 今天给大家 ...
- iOS设计模式 - 备忘录
iOS设计模式 - 备忘录 原理图 说明 1. 在不破坏封装的情况下,捕获一个对象的内部状态,并在该对象之外保存这个状态,这样以后就可以将该对象恢复到原先保存的状态 2. 本人已经将创建状态与恢复状态 ...
- iOS Swift WisdomHUD 提示界面框架
iOS Swift WisdomHUD 提示界面框架 Framework Use profile(应用简介) 一:WisdomHUD简介 今天给大家介绍一款iOS的界面显示器:WisdomHUD,W ...
随机推荐
- ASP.NET中的注释 .
之前只知道<!-- -->可以注释掉html页面中的某些部分,或者添加注释说明.今天又看到<%----%>也能添加注释,于是我不解了,google一下. <!--注释-- ...
- PopupWindow 问题集锦
1.响应返回键/响应键盘事件(onKeyListener) 最近在做PopupWindow, 发现使用PopupWindow一出现,不会响应popup外面的事件,经过资料查找,发现有两种方法可以响应外 ...
- (5)RARP:逆地址解析协议
一.简介 无盘系统的RARP实现过程是从接口卡上读取唯一的硬件地址,然后发送一份RARP请求(一帧在网络上广播的数据),请求某个主机响应该无盘系统的IP地址(在RARP应答中).感觉这个过程和上一章中 ...
- Delphi- 操作EXCEL
因工作需要,需要到操作EXCEL,先了解一下怎么读取EXCEL这个,做了一个DEMO,备注在这里 一.读取EXCEL unit Unit1; interface uses Windows, Messa ...
- PowerDesigner实用技巧小结(3)
PowerDesigner实用技巧小结(3) PowerDesigner 技巧小结 sqlserver数据库databasevbscriptsqldomain 1.PowerDesigner 使用 M ...
- 用RelativeLayout布局可以在imageview中写上文字
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 【不积跬步,无以致千里】五个常用的Linux监控脚本代码
为大家提供五个常用Linux监控脚本(查看主机网卡流量.系统状况监控.监控主机的磁盘空间,当使用空间超过90%就通过发mail来发警告.监控CPU和内存的使用情况.全方位监控主机),有需要的朋友不妨看 ...
- Centos 7 yum 安装php
yum install php php-devel 重启apache使php生效 /etc/init.d/httpd restart 此时可以在目录:/var/www/html/下建立一个PHP文件 ...
- Aizu 2450 Do use segment tree 树链剖分+线段树
Do use segment tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.bnuoj.com/v3/problem_show ...
- Aizu 2305 Beautiful Currency DP
Beautiful Currency Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...