Swift 4 学习

更新时间:2017-8-16

一、基础知识笔记

/**
 * Swift 4.0 学习
 */

import UIKit

var a = ""

var b = " "

a.isEmpty
b.isEmpty

b.count

var ruo: Character = "其"
let words = "中国人有人人械"
for heword in words {
    print("字: ",heword)
}

let a = "便是"
let b = "人间"
let c = "好时节"

var d = a + b + c

let smil = "小明"
d.append(smil)

print("\" \\ \n a \'")

多行字符串
let code = """

js test


这是一个swift多行字符串

""" let name = "李白" let type = "G" let num = 168 let desc = "长安" let deTi = "洛阳" let price = 380 let msg = """ 尊敬\(name)的乘客,您已订购\(type)\(num)\(desc)到\(deTi)的往返票,需要支付\(380 * 2)元。 """ let a = """ 海客谈瀛洲 烟涛微茫信难求 越人语天姥 云霞论坛系统好 世博五月延迟成 天台一万八千张 对此欲倒东南倾 """ 索引 a.startIndex a.endIndex a.count a[a.startIndex] a[a.index(after: a.startIndex)] a[a.index(before: a.endIndex)] a[a.index(a.startIndex, offsetBy: 3)] a[a.index(a.endIndex, offsetBy: -3)] for index in a.indices { print(a[index]) } for b in a { print(b) } 插入和删除 var a = "世界尽快头" a.insert(",", at: a.endIndex) let b = "难分离李克勤春哥?" a.insert(contentsOf: b, at: a.endIndex) //删除 remove //a.remove(at: a.index(before: a.endIndex)) //删除一个范围 let str = a.index(a.endIndex, offsetBy: -(b.count)) let bRange = str..

你可能感兴趣的:(Swift 4 学习)