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 ...
随机推荐
- Android实例-从照相机或图库获取照片(XE8+小米2)
结果: 1.如果要取本地相册的话,小米手机要注意一下,不能取网络相册. 操作: 1.两个 TButton (Button1 和 Button2) , 一个 TActionList(ActionList ...
- A Tour of Go Mutating Maps
Insert or update an element in map m: m[key] = elem Retrieve an element: elem = m[key] Delete an ele ...
- quartus II 自动生成testbench
如果自己不想写这些testbench的这些固定格式,可以在quartus里自动生成testbench文件的模板,然后往里面写信号就行了 步骤:processing->start->star ...
- Java数组的内存管理
Java数组的内存管理 Java语言是典型的静态语言,因此Java的数组是静态的,即当数组被初始化之后,该数组的长度是不可变的.Java程序中的数组必须经初始化才能使用.所谓初始化,就是当数组对象的元 ...
- vss2005使用
http://www.cnblogs.com/nianyuwen/archive/2012/06/13/2547588.html 签出状态的文件别人无法使用:
- 利用接口做参数,写个计算器,能完成+-*/运算 (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) 此方法要求能够:1.用传递过来的对象调用compute
package com.homework5; public interface Compute { //声明抽象方法 int computer(int n,int m); } package com. ...
- 关于iOS中SQLITE句柄的使用的细节
1.设计思想:给SQLITE进行封装,利用定义的类别实现方法的简洁,以便达到低耦合效果 控制器代码: #import "ViewController.h" #import &quo ...
- java中的AES 256算法遇到 Illegal key size or default parameters错的解决办法
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- Foxmail
我们在“POP3/SMTP服务”前面打钩,这样我们的QQ邮箱设置已经完成了,我们就可以在foxmail客户端上QQ邮箱了 QQ邮箱的POP3与SMTP服务器是什么? QQ邮箱 POP3 和 SMTP ...
- 判断数组(array)中是否包含某个字符(contains)
$a="a","","b" $a -contains "a" 返回 $true $a -notcontains &quo ...