playground 在學習語法方面仍是很是方便的。bash
快速運行 command + shift + enter
運行截止 shift + enter
左側工做區間 command + 0學習
playground 能夠展現你繪製的視圖,加載圖片等等之類的ui
import UIKit
import PlaygroundSupport
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
view.backgroundColor = UIColor.red
PlaygroundPage.current.liveView = view
複製代碼
須要導入頭文件 PlaygroundSupportspa
import UIKit
import PlaygroundSupport
let imgView = UIImageView(image:UIImage(named: "pic"))
PlaygroundPage.current.liveView = imgView
複製代碼
生成以後就會有多個page,原來的文件會在Untitled page 裏面,並且每一個page下面對應有source和Resource兩個文件夾,子Page下面的是不能供其餘page使用的,全局下的能夠供全部使用。3d