1. 代码注释文档规范的添加
/// 代码规范文档
struct DocumentationBootcamp: View {// MARK: PROPERTIES@State var data:[String] = ["Apples", "Oranges", "Bananas"]@State var showAlert: Bool = false// MARK: BODY// Code Folding : 代码折叠// Working copy - things to do:// 1) Fix title// 2) Fix alert// 3) Fix something else/*Working copy - things to do:1) Fix title2) Fix alert*/var body: some View {// 导航控制器NavigationView { // START: NAVZStack {// backgroundColor.gray.ignoresSafeArea()// foregroundforegroundLayer.navigationTitle("Documentation").navigationBarItems(trailing: Button("Alert", action: {showAlert.toggle()})).alert(isPresented: $showAlert) {getAlert(text: "This is alert")}}} // END: NAV}/// 这是一个前景滚动视图private var foregroundLayer: some View{ScrollView { //START: SCROLLVText("Hello")ForEach(data, id: \.self) { name inText(name).font(.headline)}} // END: SCROLLV}// MARK: FUNCTIONS/// 获取警告弹窗,带有指定的标题////// 这个函数创建并且返回警告提醒,警告框是一个基于文本的标题,/// 但是它没有消息体///```///getAlert(text: "Hi") -> Alert(title: Text("Hi"))///```////// - Warning: 这是一个不能添加消息体的警告框/// - Parameter text: 警告框的标题/// - Returns: 带有标题的警告框func getAlert(text: String) -> Alert{return Alert(title: Text(text))}
}// MARK: PREVIEWstruct DocumentationBootcamp_Previews: PreviewProvider {static var previews: some View {DocumentationBootcamp()}
}
2. 注释效果图