52 Essentials of iOS development summary of four

Source: Internet
Author: User

16, provide "all-round initialization method"

Provides an all-in-one initialization method in the class and is indicated in the document. This method should be called by the other initialization methods.

If the almighty initialization method differs from the superclass, the corresponding method in the superclass should be covered.

If the initialization method of the superclass does not apply to subclasses, then the superclass method should be covered and an exception thrown.

17 Implementing the Description method

Implements the description method, returning a meaningful string that describes the instance

-(NSString *) description{

return [NSString stringwithformat:@ "<%@:%p,%@>",

[Self class],

Self

@{@ "title": _title,

@ "Latitude": @ (_latitude),

@ "Longitude": @ (_longitude)}

];

}

If you want to print more detailed object description information during debugging, you should implement the Debugdescription method.

18. Try to use immutable objects

Try to create immutable objects.

If an attribute can only be modified inside an object, it is extended from the ReadOnly property to the ReadWrite property in the Class-continuation category.

Instead of exposing immutable collection as attributes, you should provide a method to modify the immutable collection in the object.

19 using a clear and coordinated naming method

It is easier for developers to understand the interface that is created by complying with the standard OBJECTIVE-C naming specification when naming.

The method name is concise, reading from left to right like the sentence in everyday language is good.

Do not use the abbreviated type name in the method name.

The first thing to do when naming a method is to make sure its style matches your own code or the framework that you want to integrate.

20 prefix the Private method name

Prefix the private method name so it is easy to separate it from the public method.

Do not use an underscore as the prefix for private methods, as this is reserved for Apple.

52 Essentials of iOS development summary of four

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.