The code we write will be shown to a lot of people , To make the code clear and concise , Easy to read and understand , Will be unified to comply with certain code specifications ,Objective-C The same is true of .

Main reference specifications :

1.Google Objective-C Style Guide

2.Coding Guidelines for Cocoa

Let's briefly summarize what we have come into contact with at present :

1. The maximum length of each line of code is 100(C++ Yes. 80)

2. When declaring a class or method , Pay attention to the use of spaces , If there are too many parameters, you can wrap to keep alignment ,

The same is true when calling methods , Parameters are written in one line or newline colon alignment ,

3. Naming rules

Class names are capitalized , Method initial is lowercase , The first letter of the parameter in the method is lowercase , At the same time, try to make the method name read like a sentence , Can convey the meaning of the method , At the same time, do not prefix the value method “get”

Variable names start with lowercase letters

Constants are written in lowercase letters k start , The following initials are capitalized

4. About notes

Comments are important , But except for the copyright notice at the beginning , Write as much code as possible as a document , Let others see the code directly to know the meaning , Don't worry about long names when writing code , Believe in Xcode The prompt function of .

5. Instance variables should be in the implementation file .m State or declare with @property In the form of .h Declaration in the document , Be sure to be directly in .h File statement , add @priavte, in addition , Use @private、@public, You need an indented space in front of it .

6. Guarantee as much as possible .h The simplicity of the document , It can be private API Don't make it public , Write it in the implementation file .

7.Xcode Support Objective-C/C/C++ zlc , So when you reference a header file :#import Ojbective-C/Objective-C++ The header file (Objective-C++ yes Objective-C And C++ Mixed files ),#include C/C++ The header file .

8. Write delegate The type should be weak Weak reference , To avoid circular references , When delegate After the object does not exist , We wrote delegate There is no meaning of existence. Nature needs to be destroyed ,weak And strong You can refer to the last article .

9. When you declare an instance variable, underline the variable name “_”, Local variables don't need to add .

10. Use Block when , The content is indented with four spaces ,“^” When followed by a parameter , Parameters and “{” There is a space indent between

11. It is recommended to use “#pragma mark”, Easy to read code

Other details refer to the two specifications ,Coding Guidelines forCocoa  Detailed naming requirements are also listed .

Objective-C Code specification (Code Style) More articles about

  1. Android Code specification code style

    /* * file name ( Optional ), Such as CodingRuler.java * * Version information ( Optional ), Such as :@version 1.0.0 * * Copyright notice ( Open source code generally needs to be added ), Such as :Copyright (C) ...

  2. iPhone Development :Objective C Code specification -iOS Summary

    One , About empty lines A:.h Empty line in 1, File description and header include (#import) There is no space between them 1 That's ok 2, The header contains (#import) Between , If there's a need for classification , There is no space between the categories 1 That's ok 3, The header contains (#import) And @cl ...

  3. electron course ( I'll take a look at it ): Development environment and plug-ins , VSCode debugging , ESLint + Google JavaScript Style Guide Code specification

    my electron Tutorial series electron course ( One ): electron Installation and project creation electron course ( I'll take a look at it ): Development environment and plug-ins , VSCode debugging , ESLint + Google ...

  4. stay IntelliJ IDEA Middle configuration Google Java Code Style And code formatting shortcuts

    google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...

  5. turn !!Java Code specification 、 Formatting and checkstyle Check the configuration document

    In order to standardize the code of developers . Improve code quality , The R & D center needs to start the code review mechanism . To speed up code review , Reduce unnecessary time , You can add some static checking tools for code review , In addition, we need to configure a unified coding template and code format template for the R & D center ...

  6. I'm so lucky to meet you ,The Moe Node.js Code Style Guide

    The Moe Node.js Code Style Guide  By A cute Developer @2016.9.21 >> Code is for people to read , Well formed code is the best gift for programmers :) > ...

  7. Java Code specification 、 Formatting and checkstyle Check the configuration document

    http://www.blogjava.net/amigoxie/archive/2014/05/31/414287.html File download : http://files.cnblogs.com/files ...

  8. c# Code specifications and quality inspection tools

    c# Code specifications and quality inspection tools Code style check :StyleCop Code defect checking :FxCop Code quality : Code metrics /Code Metrics StyleCop Introduce The StyleCop tool ...

  9. Web Front end code specification

    Web Front end code specification Last update time :2017-06-25 Link to original article :https://github.com/bxm0927/web-code-standards This project is used to document the . Highly maintainable front ...

Random recommendation

  1. WCF Flow in

    https://msdn.microsoft.com/zh-cn/library/ms733742.aspx

  2. Node.js Of process modular

    process Modules are used to interact with the current process , You can use global variables process visit , No need to use require The command to load . It's a EventEmitter Instance of object . attribute process Object provides a set of properties , For return ...

  3. SPOJ8222 Substrings( Postfix automaton + dp )

    The main idea of the topic : Give a string S, Make F(x) Express S All the lengths of are x In the string of , The maximum number of occurrences .F(1)..F(Length(S)) Build out SAM, Then find out Right, seek Right It can be in topological order dp..Right ...

  4. Nginx Configure specific secondary domain names

    First, resolve the secondary domain name on the domain name setting page to the public network of the server IP On , Let's say it's bbs.domainname.com Then edit /etc/nginx/sites-available/domain.com.con ...

  5. R Language learning —— Instance identifier

    > patientID<-c(1,2,3,4)> age<-c(25,34,28,52)> diabetes<-c("Type1"," ...

  6. PBRT note (5)—— Camera model

    Camera class Camera { public: // The camera can move in a certain time AnimatedTransform CameraToWorld; // The shutter is open / It's about data , It can be used to calculate dynamic ...

  7. Asp.net core Learning notes ( OData )

    2018-12-10 to update : I used to put entity Used directly for odata Exposure api For the program . If this program is our own front end , It's a great way , Because just like the front end can directly operate every table in the database ...

  8. thuwc2019 summary

    275, It's my own assessment and 350, It's the interview line In terms of play , This time it was pretty bad , On the first day, choose to fight violence instead of sign in , The next day because A The idea of the problem is biased 2h Extra time costs . Between question two and question three , I chose the hard third question and ...

  9. Provincial team training Day7 Choose some games

    [ The main idea of the topic ] Maintain a $n$ A picture of a point ,$m$ Operations , Two operations are supported : 1. Connect $(u, v)$ This side : 2. inquiry $u$ In the connection block , The maximum number of legal points that can be selected . A plan is legal , If and only if for all selected ...

  10. vue2.0 Customize Popup (MessageBox) Components

    Component template src/components/MessageBox/index.vue <!-- Customize MessageBox Components --> <template> <div c ...