OC Summary * * * hope to be helpful to everyone * * *---Gao Xiaojie

Source: Internet
Author: User
Tags control characters print object

1. NSLog is an output function provided by foundation, it is very powerful, not only can output string, also can output a variety of objects, to the later program will also see a lot of use NSLog () function.

2. NS is a prefix, and cocoa adds an "NS" prefix to all its functions, constants, and types, which is used to differentiate the function from cocoa, rather than from other packages

3. Common extensions

. C C Language source program

. cpp. CC C + + source program

. h header File

. m OC Source program

. MM Oc++ Source program

. O. Out C,c++,oc files generated after compilation

4. The Cocoa Framework includes foundation and application Kit (abbreviated as AppKit).

5. Create object syntax: [[class name Alloc] Initialization method]

6. Method type designation (return value type) method Name: (parameter type) parameter

For example:

-(Nsarray *) Arraybyaddingobject: (ID) anobject;

+ (Instancetype) Arraywithobject: (ID) anobject;

7. [Caller method name: parameter]

8. Self refers to the class object itself, which is used to invoke methods of this class of objects

9. The ID type refers to any type, and the system dynamically detects the actual type of the variable at run time.

10. Encapsulating access Control characters

@private only allow access in this class, private variables

@protected Allow access in this class and in subclasses

@public Allow access anywhere

@package allow access in the same image

Access levels from small to large:

@private--→ @package = @protected--→ @public;

The Set method assigns a value to an instance variable

Get method gets the value of the instance variable

12. Synthetic Access Methods

Using @property to define properties, use @synthesize to declare properties

13. Synthetic Access Method Special indicator

· Atomic atomicity, consider thread safety

· Nonatomic non-atomic, regardless of thread

· ReadOnly only get method, no set method

· Synthesis Set,get method of Readwrite system

· Retain reference count plus one

· Strong strong references

· Weak Weak references

14. Point syntax is a simplified notation, and the essence is still to call the Set,get party

KVC: Key-value encoding: Allows the properties of an object to be manipulated indirectly as a string.

Setvalue:forkey: Setting a value for the specified property

Valueforkey: Gets the value of the specified property

16. Handling non-existent keys

· Overriding Setvalue:forundefinedkey: Methods

· Overriding Valueforundefinedkey: Methods

17. Handling Nwil Values

· Overriding Setnilvalueforkey: Methods

18. Call Setvalue:forkeypath: Method

Call Valurforkeypath: Method

KVO: Key-value monitoring:

· AddObsever:forKeyPath:options:context:

Register a Listener

· Removeobeseverforkeypath:

Remove a listener

· Overriding the ObserverValueForKeyPath:ofObject:change:context method

20. Subclasses can get all the member variables and methods of the parent class through inheritance

21. Subclasses overriding methods of the parent class

· A subclass containing a method with the same name as the parent class is called a method rewrite;

· Attention:

· Both the method name and the parameter in the method need to be exactly the same;

· Subclasses call methods with higher precedence than parent classes

22.OC only supports single inheritance, the common things in the parent class, the personality of the things placed in the sub-class.

A. Super is used to qualify the properties and methods that the object calls it to inherit from the parent class

The packaging classes in OC are mainly NSNumber and nsvalue.

25. Print Object: The description method that needs to override the parent class is a ' self-describing ' method

26. = = and IsEqual differences:

· The address of the object in memory is unique, = = on both sides if it is the basic data type, then determine whether the content is the same, such as = = on both sides of the object, then determine whether the pointer to the object is the same, that is, whether the same object

· IsEqual determine whether the object content is the same

NSString: String

Compare strings:

· Test string content is the same: isequaltostring:

· Test whether a string is the same object: = =

· Compare string Size: Caseinsensitivecompare:

· String substitution: stringbyreplacingoccurrencesofstring:

· Determine if the string begins with a *: Hasprefix:

· Determine if the string ends with a *: Hassuffix:

· Determine the length of the string: length;

· All caps: uppercasestring;

· All lowercase: lowercasestring;

· First letter uppercase, other letters lowercase: capitalizedstring;

· Convert to bool Type: Boolvalue

· Convert to floating point type: floatvalue

· Conversion group: componentsseparatedbystring;

Components content

Intercept string

· Truncate from the beginning to the specified position, but not the character of the position: (Specify position, but not included)

Substringtoindex:

· Starts at the specified position (including the specified position character) and includes all subsequent characters:

Substringfromindex;

· To intercept a character in a range:

Nsrange;

Stitching strings

· Stringbyappendingformat:

· Stringbyappendingstring:

28. Variable string

    • Insert string: insertstring:

x, Y, which is two parameters, × is the coordinates, and y is the length.

    • Delete string: Deletecharactersinrange:nsmakerange (x, y)
    • Replacement string: Replacecharactersinrange:nsmakerange (x, y)
    • Add string: appendString:

AppendFormat:

?

Nsorderedsame: equal;

Nsordereddescending: Descending;

Nsorderedascending: Ascending;

30. Non-variable group nsarray;

    • Gets the number of elements in the array: count;
    • Access object According to subscript: Objectatindex;
    • Appends an object to the original array, returning a new array object: Arraybyaddingobject:
    • Links the elements in the array with the specified string: componentsjoinedbystring:
    • Whether the array contains an object: Containsobject:
    • Queries the specified object for the element in the array, and returns Nsnotfound:indexofobject if it does not have this element:
    • Gets the last element in the array: lastobject:

31. Sort the collection:

Sortedarrayusingcomparator:

Sortedarrayusingfunction:context:

Sortedarrayusingselector:

32. Variable array--nsmutablearray

    • Add an element to the array: AddObject:
    • Inserts an element into the array by specifying the subscript: [Insertobject:atindex:]
    • Remove the last element: Removelastobject:
    • Remove the specified element: Removeobject:
    • Remove the element that specifies the subscript: removeobjectatindex:
    • To add an array to the array: Addobjectsfromarray:
    • Replace the specified subscript element: Replaceobjectatindex:withobject:
    • Remove all objects: removeallobjects:

33. In the foundation framework, the Nsset class is provided, which is a collection of single-valued objects, and the elements in the Nsset instance are unordered, one object can only be saved, and it can be divided into mutable and immutable collection objects (Mutable collection objects, Nsmutableset)

    • ——-Nsset: A common method for immutable collections:
    • Number of objects in the collection: Count:
    • Returns all objects in the collection as an array: allobjects;
    • Returns any one of the objects in the collection: ANYOBJEC;
    • Whether the collection contains a string object with content of 2, or returns no:containsobjec:@ "2" if it contains the return yes;
    • Determine whether the same element exists in the two set, or return No:intersectsset if there is a return yes:
    • Determines whether the same element exists in two sets, or returns no if the match returns YES:

Isequaltoset:

    • Determines whether set 1 is a subset of Set 2, or returns No:issubsetofset if YES is returned:
    • Subtraction in collection: Minusset:
    • Intersection: Intersectset:
    • Set: Unionset:
    • To reassign a collection: Setset:

(Nsdictionary,nsmutabledictionary) is a collection of data consisting of key-value pairs. A key-value pair, similar to the Java map, is stored. As we look at the definition of the word in the dictionary. By (key), find the corresponding (value), key is usually a string object, or it can be any other type of object. In a Dictionary object, the value of key must be unique. In addition, the key and value of the Dictionary object cannot be null (nil), and if you need to represent a null value in a Dictionary object, you can use the Nsnull object.

    • Initialization of the Dictionary
    • Initialize with one element: Dictionarywithobject:
    • Initialize multiple elements: Dictionarywithobjectsandkeys:
    • Initializes a new dictionary that contains other dictionaries: dictionarywithdictionary:
    • Initialize the dictionary with the contents of the file: Dictionarywithcontentsoffile:
    • Sort the key value of the dictionary:

Keyssortedbyvaluewithoptions:usingcomparator:

Keyssortedbyvalueusingselector:

Keyssortedbyvalueusingcomparator:

    • Variable dictionary-nsmutabledictionary
    • It inherits from Nsdictionary

The Nspredicate class is provided in 35.Cocoa, specifying the conditions of the filter to preserve the eligible objects.

    • The addition of the operation symbol, the predicate does not distinguish between size and:&&, and;
    • Begin Swith Check if a word starts with * *
    • ENDSWITH Check that a character is a * * end
    • CONTAINS Check contains a character
    • Fuzzy query:--like check contains a character

36. Sequential Enumerator: Objectenumerator

Reverse Enumerator: Reverseobjectenumerator

37. Word prefixes for general methods:

    • Ways to add elements: Add start
    • Methods for deleting elements: Remove start
    • Methods for replacing elements: replace start
    • Dynamic Incoming property name:%K
    • Dynamic Setting property value:%@

OC Summary * * * hope to be helpful to everyone * * *---Gao Xiaojie

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.