Playground
- Swift Playground首次公布与WWDC2016
- 最开始是为了让人人都能愉快的学习Swift编程
- 但发展至今,这个工具越来越强大
- iPad APP Playgrounds
创建一个Playground项目
简介
- extension -> 定义扩展
- 让打印出的数据更加可视化一些,如果没有这个,最后一句打印只能打印出一个对象
视图可视化
//ViewController1.swiftimportFoundationimportUIKitpublicclassViewController1: UIViewController { publicoverridefuncviewDidLoad() { super.viewDidLoad() letbutton=UIButtion(type: .custom) button.frame=CGRect(x:0,y:200,width:300,height:50) button.setTitle("点击跳转",for: .normal) button.setTitleColor(.white, for: .normal) button.backgroundColor= .bluebutton.addTarget(self, action: #selector(onButtonClick),for: .touchUpInside) view.addSubview(button) } @objcfunconButtonClick() { navigationController?.pushViewController(ViewController2(), animated: true) } }
//ViewController2.swiftimportFoundationimportUIKitpublicclassViewController2:UIViewController { publicoverridefuncviewDidLoad() { super.viewDidLoad() letlabel: UIlabel=UILabel() label.frame=CGRect(x:0,y:200,width:300,height:50) label.text="页面2"label.textColor= .whitelabel.backgroundColor= .redview.addSubview(label) } }