Swift(一)常量和变量

2017-06-27  本文已影响132人  YvanLiu

更新:2018.05.24

整理了一下demo:SwiftDemo


写在前面

Swfit语言是苹果开发者工具部分总监Chris Lattner创作的,发布于WWDC2014
Swift建立在Object-CC语言的基础之上,让编程更简单、更容易、更灵活。
经过几次改版之后,现在的3.0版本基本已经趋于稳定,所以同志们,是时候搞一下了。

常量

const NSString *str = @"xxxx";
 let num     = 70
 let name    = "yvan"
 let width   = 69.50
let age:Int
age = 18
let text = "The text is"
let width = 20
let textWidth = text + String(width)

或者这样:

let apples = 2
let oranges = 3
let sum = "I Have \(apples+oranges) fruits"

变量

var object = "nothing"
var notes = 10
 var names = ["Li Lei","Han Meimei","Lusy"]
names[0] = "Li Bai"
names.insert("Tom", at: 0)
var people = ["name":"Li Lei","age":"10","sex":"men"]
 var texts = [String]()
var dates = Dictionary<String,String>()

写在后面

let value:Double = 20
上一篇 下一篇

猜你喜欢

热点阅读