OBJECTIVE-C Study Notes
1. Use #import Import header file, General OSX command line development using <foundation/foundation.h>, GUI development use <Cocoa/Cocoa.h>
The string in 2.OC is no longer an array, but instead becomes an object of type NSString, where the string is the object, and when the static string is assigned, you should use @ To do the identification, for example @ "HelloWorld"
3.OC is true and false bool type, while true yes false for no, accounting for eight bits, the system relies on the lowest bit to determine, the lowest bit is 0 for no, the lowest bit is not zero, is yes, so, when compared with bool, should compare with no
4./tmp is the system cache directory, the system restarts when the time is emptied
The 5.id type is a generic pointer to OC, which can point to any object, but it is best not to misuse
The interface definition mode for 6.OC is as follows
@interface
{
The @ property's access rights
Property value
}
-(return type of method) method name: (type of parameter 1) parameter name, (type of parameter two) argument name;
@end
The 7.OC interface is implemented as follows
@implemention
-(return type of method) method name: (type of parameter 1) parameter name (type of parameter two) argument name
{
function Implementation/method implementation
}
@end
The 8.OC call method uses brackets, such as [instance pointer method name: Parameter 1, parameter 2]
9. In the implementation of the class, the instance variable of the class can be accessed directly, because the OC compiler hides a parameter self when directly accessing it.
10. The simplest way to generate a new instance is [class name new] (not recommended later)
11,OC itself does not support multiple inheritance, but it can be implemented with a delegation mechanism to implement multiple inheritance
12. A method in a subclass that wants to invoke the parent class can use the Super keyword, for example [Super init]
13. When defining an interface, you can specify the inherited parent class, as in the following example
@interface Interface Name: Parent class name
@end
14. Use NSLog to output, similar to printf
15.NSLog can print the object, adapt to the%@ parameter, so the system will automatically call the object's description method
16. The method of accessing the property, using the set+ attribute name method to use the property name directly, assuming that the property is xxx;
-(void) SETXXX: (id) XXX-(id) xxx;
17.oc uses the. m format of the source file and the. h format header file, which is usually stated in the. h file, implemented in the. m file
[email protected] class Name This keyword generally represents the import class, which is used in the. h file when you do not want to include the header file when you Use the keyword
19. Scope structure Body Nsrange, indicating the starting point and size of the number, the parameters are unsigned shaping, the assignment has function nsmakerange () function
20. Coordinate structure body cgpoint, parameters are floating point type, representing coordinates, Cgpointmake fast assignment
Graphical structure Body cgsize parameter is floating point, cgsizemake fast Assignment
The rectangular structure CGRect contains two structure-type parameters and is quickly assigned to CGRectMake
21. Methods of String class NSString
stringWithFormat creating a new string
Length gets the number of strings
Isequaltostring string comparison
Compare string comparison
Nscompareresult comparison structure enumeration, value including Nsorderascending, etc. three
Hasprefix detects whether a string begins with a specified string
Hassuffix detects whether a string ends with a specified string
Rangeofstring detects if there is a specified string in the string that does not return Nsrange in location is Nsnotfound
22.NSString is immutable at run time and requires nsmuteablestring if run-time variable strings are required
Stringwithcapacity specifying the capacity of initialization
AppendString additional substrings
AppendFormat attaching a formatted string
Deletecharactersinrange Delete a character at a specified position in a string
Because Nsmuteablestring is a subclass of NSString, NSString's function nsmuteablestring can be used
22.NSArray
Nsarray can be placed in any type of object, but cannot hold native data types
Arraywithobjects initialization, specifying the original list of data
Count gets the number of elements
Objectatindex getting elements of a specific location
Componentsjoinedbystring uses a specific string to link all elements into a new string to return
22, variable group Nsmutablearray
Arraywithcapacity specifying the capacity of initialization
AddObject adding objects at the end
Removeobjectatindex removing elements from a specified position
Objectenumerator getting an enumerator for an array object
23. Enumerations, using enumerators
while (id thing = [enum Nextobject])
{
//dosomething
}
24. Quick Enumeration
New features after 10.5, while (nsstring* str in array) {//dosomething}
25.NSDictionary Dictionary
Dictionarywithobjectsandkeys creating a key-value pair, initializing the object
Objectforkey getting objects by key
26. Variable Dictionary nsmutabledictionary
Dictionarywithcapacity Initializing a mutable dictionary, specifying the capacity
SetObject Forkey Adding key-value pairs
Removeobjectforkey Delete a key-value pair
27. For NSString and Nsarray, do not inherit, preferably using composite
28.NSNumber Numerical class
Used to boxing native data types
Numberwithchar numberwithint numberwithfloat Numberwithbool Boxing
Charvalue intvalue floatvalue boolvalue stringvalue Unpacking
29.NSNumber is actually a subclass of Nsvalue, Nsvalue can encapsulate any value,
Valuewithbytes specify data length and data type to be boxed
GetValue for extracting values
30.NSNull
Nil boxed data structure, only one method null
The 31.oc method is divided into two types, the instance method and the class method, the use of-defined is the instance method uses the + definition method is the class method, the class method can be called directly through the class name when there is no instance, such as the Init method, as follows
Class method +void init: (int) A, (int) b;
Instance method-void init: (int) A, (int) b;
OBJECTIVE-C Study Notes