[swift]的简单使用常量变量。字典 数组的初始化
2016-09-08 21:02
701 查看
//let 声明常量
let label ="the width is"
let width =94
let widlabel = label +String (width)
/**
* the width is94
*/
print(widlabel)
//显式指定类型
let exp :Double =70
/**
* 70.0
*/
print(exp);
let apples =3
let oranges =5
let applesum ="i have
\(apples) apples"
let fruitsum ="i have
\(oranges+apples)fruit"
print(applesum)
/**
i have 3 apples
*/
print(fruitsum)
/**
i have 8 fruit
*/
let apps =70.1
let hello = "hello\(apps)"
print(hello)
//使用 []来创建字典和数组,并使用键(key)值去访问数组
//数组的创建
var shoplist = ["catfish" ,"water","tulips"]
shoplist[1] ="water is clear"
print(shoplist)
//["catfish", "water is clear", "tulips"]
//字典的创建用:相隔
var occp = ["mack":"1","yew":"2"]
occp["jayne"] ="public"
//为字典添加新元素
print("occp is\(occp)")
// occp is ["yew": "2", "mack": "1", "jayne": "public"]
var shops = ["catfish","water","tuips"]
shops[1] =
"water is clear"
//键
:值
等号
左右俩边需要留空格
var occp = [
"mac":"1","windows":"2"]
occp["jsr"] =
"pulic"
print(occp["jsr"])
print("occp is
\(occp)")
print("shops is\(shops)")
//要创建一个空数组
或者字典
,使用初始化语法
let emptyArr = [String]()
//objectForKey(aKey: AnyObject) -> AnyObject?
let dict3 : [String :
Int] = [:]
print(dict3)
print(emptyArr)
//[:]
//[]
let label ="the width is"
let width =94
let widlabel = label +String (width)
/**
* the width is94
*/
print(widlabel)
//显式指定类型
let exp :Double =70
/**
* 70.0
*/
print(exp);
let apples =3
let oranges =5
let applesum ="i have
\(apples) apples"
let fruitsum ="i have
\(oranges+apples)fruit"
print(applesum)
/**
i have 3 apples
*/
print(fruitsum)
/**
i have 8 fruit
*/
let apps =70.1
let hello = "hello\(apps)"
print(hello)
//使用 []来创建字典和数组,并使用键(key)值去访问数组
//数组的创建
var shoplist = ["catfish" ,"water","tulips"]
shoplist[1] ="water is clear"
print(shoplist)
//["catfish", "water is clear", "tulips"]
//字典的创建用:相隔
var occp = ["mack":"1","yew":"2"]
occp["jayne"] ="public"
//为字典添加新元素
print("occp is\(occp)")
// occp is ["yew": "2", "mack": "1", "jayne": "public"]
var shops = ["catfish","water","tuips"]
shops[1] =
"water is clear"
//键
:值
等号
左右俩边需要留空格
var occp = [
"mac":"1","windows":"2"]
occp["jsr"] =
"pulic"
print(occp["jsr"])
print("occp is
\(occp)")
print("shops is\(shops)")
//要创建一个空数组
或者字典
,使用初始化语法
let emptyArr = [String]()
//objectForKey(aKey: AnyObject) -> AnyObject?
let dict3 : [String :
Int] = [:]
print(dict3)
print(emptyArr)
//[:]
//[]
相关文章推荐
- Swift 学习笔记 2-简单值(变量、常量、数组、字典 )
- Swift 常量、变量定义使用 String和简单控件的使用
- iOS swift 创建各种变量,常量,字典,数组等
- Swift 学习第一天 常量 变量 数组和字典
- swift学习之定义常量、变量、字典、数组
- swift 之 数组集合字典的简单使用
- swift学习笔记(一)(常量、变量、数据类型、字符串的拼接、数组、字典)
- 使用Swift 字典模型互转 就是这么简单
- 数组的初始化和简单使用
- C语言返璞归真之修改const常量和使用变量定义数组长度
- Swift学习——变量var和let常量的使用方法(一)
- Swift中的常量和变量简单概述
- 九宫格 Swift提供经典的数组和字典两种集合类型来存储集合数据,使用数组实现一个九宫格程序,
- Swift3 - String 字符串、Array 数组、Dictionary 字典的使用
- 7、Swift数组的简单使用
- Swift学习笔记(二十四)——常量数组和常量字典
- swift学习笔记(变量、数组和字典)
- Swift数组的简单使用
- 变量,常量,字符,字符串,数组的声明及初始化
- [Swift] 输出语句 简单赋值 转换类型 数组 字典