SwiftUI-Day1 简单数据类型

文章目录

  • 吐槽
  • 结果
  • Variables
  • Constants

吐槽

Xcode升级,什么appdelegate都没有了,现在全是swiftUI。。。
下面的代码是playground的代码,不是swiftUI View。
参考资料:https://www.hackingwithswift.com/100/swiftui/1
时间:09 October, 2020

结果

运行快捷键:shift+command+回车
删除当前行:option+D
SwiftUI-Day1 简单数据类型_第1张图片

Variables

import UIKit

// Variables
//integer
var age = 38
var population = 9_000_000
// double
var pi = 3.1415
//booleans
var awesome = true
//string
var str = "Hello, playground"
// multiline with line breaks
var multiLineString = """
This
goes
like
this
"""
// multiline without line breaks
var multiLIne = """
This \
goes \
like \
this
"""

// String interpolation
var sentence = "The value of pi is \(pi)"
var result = "\(multiLIne): \(sentence)"


Constants

import UIKit

// Constants
let taylor  = "swift"
let album: String = "Reputation" // with type annotaion
let year: Int = 1989
let height: Double = 1.78
let taylorRocks: Bool = true

你可能感兴趣的:(swiftUI)