Swift 基本数据类型,常/变量声明(一)
2016-03-15 11:57
459 查看
https://github.com/Zhangjingwang1993/Swift.git
/// 项目不太忙, 撸撸Swift
/// 项目不太忙, 撸撸Swift
变量 使用var声明
var str:String = "dd" str = "GG" print(str)
常量 使用let声明
let count:Int = 16 print(count)
整型
Int, Int8, Int16, Int32, Int64 UInt, UInt8, UInt16, UInt32, UInt64
浮点型 ,布尔型
Float, Double, Bool
获取字符串的数量 // str = GG
print(str.characters.count) // 2
检查字符串是否有特定的前缀和后缀 pre/suf
let sttPre = "hello.com" if sttPre.hasSuffix(".com33"){ print("YES") }else{ print("NO") }
还可以”()”
let name1 = "helloworld" let msg = "Welcome to \(name1)" print(msg) // Welcome to helloworld
大小写转换
通过字符串的uppercaseString、lowercaseString、capitalizedString 属性来访问一个字符串的大写/小写/首字母大写
字符
var char:Character = "$" print(char)
元组
let myCode = (one:"ZJwang", two:123) print("\(myCode.one)")
相关文章推荐
- IOS开发系列之Swift_UI_Btn
- IOS开发系列之Swift_UI_Btn
- IOS开发系列之Swift_UI_Lab
- OC与Swift混编
- Swift-2.7闭包
- 《千万别说swift不用管理内存!这么多坑赶快记下》
- Swift的两个小窍门
- OC使用use_frameworks!添加swift,其他库头文件不提示
- swift 接水果游戏ios源码
- swift 接水果游戏ios源码
- swift系统学习第一章
- Swift基础3.3——便利构造函数
- Swift基础3.2——重载构造函数
- Swift基础3.1——构造函数
- Swift基础2.1——闭包
- Swift基础2.1——函数
- Swift基础1.5——基本语法——集合
- Swift基础1.4——基本语法——字符串
- Swift基础1.3——基本语法——控制流
- Swift基础1.2——基本语法—Optional 可选项