Write high-quality iOS code-Objective-C 2.0 Reading Notes and writing high-quality code

Source: Internet
Author: User

Write high-quality iOS code-Objective-C 2.0 Reading Notes and writing high-quality code
Write high-quality iOS code-Objective-C 2.0 Reading Notes

This book was written at the beginning of the year. It feels good. I have introduced a lot of tips, but I don't pay much attention to it on weekdays.

Chapter 2 familiarity with Objective-C

There is nothing to introduce in this Chapter

Article 1st: Learn about the origins of Objective-C language Article 2nd: introduce as few header files as possible in Class header files Article 3rd: Use the literal syntax and use less equivalent methods Article 4th: multi-purpose type constants, less use # define preprocessing commands

You need to understand why you need to use less # define pre-processing commands. Then, decide which one to use.

Article 12: Use enumeration to indicate status, options, status codes Chapter 4 objects, messages, and runtime Article 1: understanding the concept of "attribute"

Attributes: variables + Methods + attributes

7th: Try to directly access instance variables within the object

Performance Optimization

Article 8th: understanding the concept of "Object equality" Article 9th: Hiding implementation details in the "class family mode"

Factory Model

Article 3: using Correlated objects in existing classes to store Custom Data

Class add attributes

Article 11th: understanding the role of objc_msgSend

Transmit messages

Article 21: Understanding the message forwarding mechanism

Dynamic Method resolution: Send resolveInstanceMethod to the current class: Check whether the method is dynamically added to the class

Fast message forwarding: Check whether this class implements forwardingTargetForSelector: If yes, this method is called. If the returned object of this method is not nil or not self, the message is resent to the returned object.

Standard Message forwarding: runtime sends methodSignatureForSelector:, the method signature corresponding to the Selector is obtained for the message. If the returned value is not null, the message is forwarded through forwardInvocation. If the returned value is null, The doesnocognizeselector is sent

Article 3: Use the "method allocation technology" to debug the "black box method"

Method swizzling. It is not recommended to abuse it.

Article 14th: Understanding the intention of "Class Object"

It's actually c-oop.

Chapter 2 interface and API design Article 1: Avoid namespace conflicts with prefixes Article 3: Provide the "All-Around Initialization Method" Article 3: implement the description method Article 3rd: Try to use immutable objects

If you don't pay attention to this, there will be problems.

19th: Use clear and coordinated naming rules 20th: Add a prefix to a private method name

If you write too much, you will know that you will not do it. Sooner or later, you will encounter problems. If you do not, you should write too little.

Article 21st: Understanding Objective-C Error Model article 22nd: Understanding NSCopying protocol Chapter 1 Protocol and classification Article 4th: communication between objects through the delegate and Data Source Protocol Article 23rd: spread the implementation code of the class to 25th of the several categories that are easy to manage: always add 26th prefix to the category name of #### third-party classes: do not declare 27th attributes in a category: Use "class-continuation Classification" to hide implementation details. Article 28th: provide anonymous objects through protocols

A duck is a duck.

Chapter 2 Memory Management Article 1: Understanding reference count

One of the three basic methods of Memory Management

Article 30th: Simplified reference count with ARC

Use arc to make programming more concise

31st: only the reference is released and the listener is removed in the dealloc method. 32nd: When writing "exceptional security code", pay attention to the memory management issue. 33rd: avoid retaining the ring with weak references: use "Auto Release pool block" to reduce the memory peak by 35th: Use "zombie object" to debug memory management problems by 36th: Do not use retainCount chapter 6th block and hub to distribute 37th messages: understand the concept of "Block"

Closure (the structure of the environment where local variables are closed in function objects) specific implementation under oc

38th: Create 39th typedef rules for common block types: Use a handler block to reduce code dispersion by 40th: Do not use a reserved ring when a block references its object
#define DEF_WEAKSELF                        __weak __typeof(self) weakSelf = self;#define DEF_STRONGSELF                      __strong __typeof(weakSelf) self = weakSelf;
Article 5: multi-purpose Dispatch queue, less synchronization lock, 41st: multi-purpose GCD, less use of the performSelector series, 42nd: master the use time of GCD and operation queue, 43rd: through the Dispatch Group mechanism, run the following 45th tasks based on system resources: Use dispatch_once to run the thread-safe code only once: Do not use dispatch_get_current_queue

Beware of deadlocks

Chapter 2 system framework article 1: familiar with the system framework article 2: multi-module enumeration, less for loop Article 2: Seamless bridging of 7th entries for collections with custom memory management semantics: use NSCache instead of NSDictionary to build a cache: 51st code for streamlining initialize and load: do not forget that nsttionary retains the target object.

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.