swift:基本数据类型
2016-03-03 22:02
387 查看
//: Playground - noun: a place where people can play
import UIKit
//整数类型
let int_a =10
let int_b :Int
let int_c :Int
= 10
//注意不能 let int_c (即是在定义常量或者变量时,在隐示声明的时候必须初始化)
//字符串
let string_a ="i like eat"
let string_b:String
let string_c:String
= "i like eat"
//类型强制转换
let apple ="the number of apple is "
let number =10
let number_apple=apple
+ String(number)
print("the number is\(number)")
//
浮点数
let float_a =1.0
let float_b:Float
let float_c:Float=1.0
let double_a =1.99
let double_b:Double
let double_c:Double=1.99
//布尔类型
let bool_a=true
let bool_b=false
let bool_c:Bool
let bool_d:Bool=true
//数组与字典
let emptyArray = [String]()
var array1 = ["aa","bb",12]
let emptyDictionary =Dictionary<String,Float>()
var dictionary1 = ["xiaoming":10,"xiaohong":12]
dictionary1["xiaofei"]
= 12//添加元素
print(dictionary1)
//枚举
enum Person{
case
小明
case
小红
case
小花
}
let person1:Person = .小明
let person2:Person = .小红
let person3:Person = .小花
let person:Person =
person2
switch person{
case .小明:
print("是小明")
case .小红:
print("是小红")
case .小花:
print("是小花")
}
import UIKit
//整数类型
let int_a =10
let int_b :Int
let int_c :Int
= 10
//注意不能 let int_c (即是在定义常量或者变量时,在隐示声明的时候必须初始化)
//字符串
let string_a ="i like eat"
let string_b:String
let string_c:String
= "i like eat"
//类型强制转换
let apple ="the number of apple is "
let number =10
let number_apple=apple
+ String(number)
print("the number is\(number)")
//
浮点数
let float_a =1.0
let float_b:Float
let float_c:Float=1.0
let double_a =1.99
let double_b:Double
let double_c:Double=1.99
//布尔类型
let bool_a=true
let bool_b=false
let bool_c:Bool
let bool_d:Bool=true
//数组与字典
let emptyArray = [String]()
var array1 = ["aa","bb",12]
let emptyDictionary =Dictionary<String,Float>()
var dictionary1 = ["xiaoming":10,"xiaohong":12]
dictionary1["xiaofei"]
= 12//添加元素
print(dictionary1)
//枚举
enum Person{
case
小明
case
小红
case
小花
}
let person1:Person = .小明
let person2:Person = .小红
let person3:Person = .小花
let person:Person =
person2
switch person{
case .小明:
print("是小明")
case .小红:
print("是小红")
case .小花:
print("是小花")
}
相关文章推荐
- 错误处理与异常抛出_Swift基础知识学习
- 获取对象类型(swift)
- Swift析构器
- 枚举_Swift基础知识学习
- Swift中的get和set方法
- Swift 基础学习(函数)
- 大熊的swift学习笔记(三)
- iOS开发-swift基础学习三
- iOS开发-swift基础学习二
- Swift Release模式下屏蔽NSLog()
- 基于swift语言iOS8的蓝牙连接(初步)(转帖)
- swift 创建tableView 并实现协议
- Swift 基础学习(判断语句)
- Swift 基础学习(字典)
- swift资料收集
- swift: Swift中static和class的使用
- swift 快速奔跑的兔几 本节的内容是:iOS上基于文档的应用程序
- Swift2.0(17)泛型技术
- Swift2.0(17)内存管理ARC
- Swift2.0(16)分类与协议