The note specification for the--swift coding specification from the zero-starting Swift Learning note (day):

Source: Internet
Author: User

learn from the beginning of the zero Swift "Study notes ( Day )--Swift Annotation Specification for Coding specification: file comments, Documentation comments, code comments, using landmark annotations  

original articles, welcome reprint. Reprint Please specify: Dongsheng's blog

said before Swift There are two kinds of syntax for annotations: single-line Comments ( // ) and multi-line annotations ( /*...*/ ). Here is a description of their usage specifications.  

    1. File comments

A file comment Adds a comment at the beginning of each file, and the file comment usually includes the following information: Copyright information, file name, module, author information, historical version information, file content and function.

Here is an example of a file comment:

/*copyright (C) eorientinc.  All rights reserved.see license.txtfor This sample ' s licensing information Description:this file contains thefoundational Subclass of Nsoperation. history:15/7/22:created by Tonyguan.15/8/20:add Socketlibrary15/8/22:add Math library*/


This note only provides copyright information, file content and historical version information, etc., and the file comments should include the content according to their actual situation.  

    1. Document comments

      Documentation Comments Span style= "LETTER-SPACING:0PX;FONT-SIZE:16PX;" >api

A document comment is a little bit of a single-line comment ( // ) and multi-line annotations ( /*...*/ after doing a little "hands and feet", it becomes a document comment, a single-line document comment ( /// ) and multi-line document comments ( /**...*/ ).

The following code example:

Import Foundation/** The protocol that types could implement Ifthey wish to be notified of Significantoperation Li    Fecycle events.*/protocol operationobserver{///invoked immediately prior to the ' operation ' s ' Execute () ' method. Func Operationdidstart (Operation:operation)}


Documentation comments are used in the code.

You can use some tools to generate these document comments API file  

    1. Code comments

Process Document comments in program code also need to add code comments in some key places, document comments are generally for some people who do not see the source code to see the Help document, and code comments for reading source code for reference. Code comments typically take a single-line comment (//) and a multiline comment (/*...*/).

Sometimes it will be in the code The end of the note , which requires a very short comment content, should have enough whitespace to separate the code and comments. The end note Sample code is as follows:

Init (timeout:nstimeinterval) {self.timeout = timeout//Initialize}

    1. Use landmark notes

As the coding process progresses, the amount of engineering code increases, and any code that can be quickly found in this large amount of code, or has just been modified?

in the Swift use landmark annotations in your code, and then you can use the Xcode The tool quickly finds it in the code. There are three landmark notes:

  • MARK a comment that is used for a method or function.

  • TODO , indicating that there is no completion of the code here, but also processing.

  • fixme , which means the code is modified here.

     jump Bar

Class viewcontroller:uiviewcontroller,       uitableviewdatasource,  uitableviewdelegate {     var listteams: [[string:string]]!      override func viewdidload ()  {         super.viewdidload ()         ...    }      override func didreceivememorywarning ()  {         super.didreceivememorywarning ()         //todo:   Release Resources                                   // Use TODO comments     }     // MARK: UITableViewDataSource  Protocol Method              //using the Mark annotation     func tableview ( tableview: uitableview,         numberofrowsinsection  Section: int)  -> Int {        return  Self.listteams.count    }     func tableview (TableView:  uitableview,         cellforrowatindexpath indexpath:  nsindexpath)  -> UITableViewCell {          let cellidentifier = "Cellidentifier"          let  cell: UITableViewCell! = tableView           .dequeuereusablecellwithidentifier (cellidentifier,                 forindexpath: indexpath)  as? uitableviewcell        //  FIXME:  Modify bug                                // Using Fixme annotations         let row = indexPath.row         let rowdict = self.listteams[row] as[string:string]         ...        return  cell    }     // MARK: UITableViewDelegate  Protocol approach                     //using the Mark annotation     func tableview (tableview: uitableview,         &nBsp;  didselectrowatindexpath indexpath: nsindexpath)  {         ...    }}


The above code uses three landmark annotations, followed by a colon after use (:).

What if I use it after the comment? Open Xcode 's jump Bar, for example, these landmark notes are shown in bold in the drop-down list, and clicking on a list item jumps to the comment line.

650) this.width=650; "title=" image1.jpg "src=" http://s3.51cto.com/wyfs02/M02/7C/F2/ Wkiom1bdaulahdyraagmhbs367m582.jpg "alt=" Wkiom1bdaulahdyraagmhbs367m582.jpg "/>



Welcome to follow Dongsheng Sina Weibo@tony_Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
650) this.width=650; "title=" 00.png "src=" http://s4.51cto.com/wyfs02/M00/7C/F2/wKiom1bc-5Cg7GPkAAAs2MBEZnc217.png "alt=" Wkiom1bc-5cg7gpkaaas2mbeznc217.png "/>
More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php


This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://tonyguan.blog.51cto.com/701759/1748343

The note specification for the--swift coding specification from the zero-starting Swift Learning note (day):

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.