Objective-C basic learning summary, objectivec Basics

Source: Internet
Author: User
Tags notification center

Objective-C basic learning summary, objectivec Basics

1. (1) process orientation: an event-centric programming philosophy (2) Object-oriented: An Object-Oriented Programming philosophy 2. get and set are used to access and modify the attribute values of objects. Note: The naming rules in OC do not require the get prefix eg: int age = [person getAge] For the get method name. (false) int age = [person age]; (true) 3. self is used to call instance variables and methods of this Class Object. super is used to steal methods inherited from the parent class. 4. @ property: automatically generates get and set methods for a property. 5. class can call the class method, but cannot call the instance method, but you can access the instance method by creating an object. 6. convenience constructor: a method for quickly creating objects. In essence, Initialization is encapsulated to facilitate external use (I .e., assigning values at the same time of init. singleton mode: This mode ensures that there is only one instance in a class in the system, and the instance is easy to access, so as to facilitate the control of the number of instances and save resources. (1) main features: a consumer class has only one instance; the consumer must create the instance by itself; the consumer must also provide the instance to the entire system. (2) implementation perspective: the observer class only provides private constructor; the observer class definition contains a static private object of this class; the aggregate class provides a static common function to create or obtain its own static private object ). 8. factory model: similar to C2B 9 in Internet business model. three features of object-oriented: encapsulation, inheritance, and polymorphism (1) Role of Object-oriented Inheritance: reduce code duplication and reduce program design time; Role polymorphism definition: the same type, multiple forms of polymorphism: solves redundancy, scalability, and maintainability. Note: there must be an inheritance relationship in the polymorphism condition, and the subclass overrides the parent method, the variables declared by the parent class point to the sub-class (2) classes in OC are single-inherited (3) method Rewriting: classes must be inherited, the define subclass method is the same as the parent class method 10. the length of a string is obtained using the length attribute. (1) extended string: str1 = www str2 = baidu

StringByAppendingPathComponent --> www/baidu
StringByAppendingPathExtension --> www. bai
StringByAppendingString --> wwwbaidu
StringByAppendingFormat --> wwwbaidu

(2) Basic data types cannot be stored in arrays (3) the set is unordered and the stored objects cannot be repeated. memory Management: Focus ------------- golden rule ------------------- when alloc, retain, and [mutable] copy are used for objects, the corresponding release or autorelease transform (1) must be used) basic data types do not require memory management (int, long, double, float, struct, char) (2) When an owner performs retain, alloc, copy operations, when release and autorelease are used, the ownership of the object is released. (3) When copy, alloc, and new are used to construct the object, retainCount is 1; the retainCount method of the invoke call object is increased by 1 retainCount, And the release method of the call object is reduced by 1 retainCount. When the retainCount of the object is set to 0, delloc is automatically called to automatically release the object memory, otherwise, the memory allocated to the object will be occupied all the time. (4) Note: The attribute memory management a class has a property declaration using retain, copy, you must release the attribute in the delloc method of this class (5) when the autoReleasepool consumer object gives ownership to the recent automatic release and is fully managed by it (nested with the automatic release pool) when the consumer Automatically releases the pool for destruction, A release message is sent to all objects in the message 12. ARC automatic reference count management memory (1) cannot use releaseCoun attribute t print reference count ---------------------------------- (2) Tired delloc method can no longer call [super delloc]; ------------------------------ (3) whether a heap memory is released depends on whether the _ strong type Stack pointer is 0. If it is 0, the memory is released, regardless of the _ weak pointer, weak is mainly used to prevent cross-reference (proxy mode) (4) ARC's golden rule: as long as there is a variable (pointer) pointing to an object, the object will be saved in memory (5) strong is equivalent to retain. weak cannot be used in non-ARC (6) in ARC. The delloc method is generally not required. because we can't use release of object; (7) note: When KVO and notify are used, must removes (8) from the delloc method) disable ARC Build Phases for some files --> Comile Sources --> add selected files -->-fno-objc-arc (9) for which files use ARC Build Phases --> Comile Sources --> Add a selected file -->-fobjc-arc (10) X-xode automatic conversion tool is recommended only once. Back up the code and code before using it, back up the code. Otherwise, the consequences will be unimaginable. 13. Categories, protocols, and extensions (extension methods)(1) modify the source code and create such sub-classes (2) category: the handler adds one or more new methods to an existing class. The handler can inherit the handler class as a part of the original class, same as the method in the original class (Add a new method for the existing class. (You can only add methods, but not instance variables) Note: You can only write methods in the category. You cannot add member variables. You can add multiple categories to the same category, however, you cannot override methods of existing classes with duplicate names, but after overwriting, you cannot call the original method (3) Extension: the category defined in the class implementation file, extension is an anonymous category. A private method is a private method. (You can add methods or instance variables) (4) Protocol: Declares methods that can be implemented by other classes. The protocol is not a class, but an interface that can be implemented by other objects (5) the similarities and differences between instancetype and id are the same: both can be used as the return type differences of Methods: ️ instancetype can return objects of the same type as the class of the method, and id can only return objects of unknown type, ️ itancetype can only be used as the return value. It cannot be used as the parameter 14.KVC & KVO (1) KVC like id. That is, NSKeyValueCoding is an informal protocol, KVO is a key technology based on KVC implementation to provide a mechanism to indirectly access the attributes of objects. keyValueObserve can observe the value of changing the KVC key Path of an object (2) KVO usage steps: listener: The Listener method automatically calls when the property value changes. (3) Notification: // get notification center + (nsicationicationcenter) /// send notification-(void) postNotification :( NSNotification *) notification

 

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.