Development Environment
If you write a demo by yourself, set the file name in [Mac OS X] --> [application] --> [command line tool] (command line template) and select foundation system library as the type.
Nslog output format
• % @ Object
• % D, % I integer
• % U unsigned integer
• % F floating point/double-Character
• % X, % x binary integer
• % O octal integer
• % Zu size_t
• % P pointer
• % E floating point/Dual-word (Scientific Computing)
• % G floating point/double-Character
• % S c string
• %. * S Pascal string
• Only one character can be output for % C. If there are multiple characters, select the last char as the output.
• % C unichar
• % LLD 64-bit long integer (long)
• % LlU unsigned 64-bit long integer
• % Lf 64-bit dual-Text
Note: When multiple variables are output, you need to write multiple % I, % d, and so on (personal perception)
int r = 5;int p = 3;NSLog(@"the number is %i %i",p,r);
Key-value Encoding
Definition: a mechanism for indirectly accessing object attributes (similar to reflection in Java)
1. This mechanism can access object attributes without calling access methods and variable instances.
2 The default implementation method is declared by nsobject (ancestor) and nskeyvaluecoding (class directory of an informal protocol ).
3. attributes with object values, including pure value type, structure, non-object parameters, and return types are recognized and automatically encapsulated/unblocked.
Use the following two methods:-valueforkey: And-setvalue: forkey: (the two methods cannot be understood. Let's look at the definition of the method)
1. send messages to objects in the form of strings
2. If the setter method does not exist, the getter method searches for the instance variables named _ key (an attribute naming method with advanced annotations containing wood and wood) or key at a glance, you can obtain the object value without the getter method. You do not need to directly access the object through the Object Pointer (I Feel Like Nb)
3-setvalue: forkey: Set the object value or valueforkey to obtain the object value. If the instance variable of the object is of the basic type (char, Int, float, bool .....) we need to encapsulate the data (such as isnumber)
Here is a code for accessing private variables
// Here the book class only defines a private property // ------------------------------------------------------- # import "book. H "@ implementation book: nsobject {@ private nsstring * _ name;} @ end // This is main. the M program // here deliberately writes the parameters in forkey as name, which can also be implemented. You can see an Access Mechanism // ------------------------------------------------- # import <Foundation/Foundation. h> # import "book. H "int main (INT argc, const char * argv []) {@ autoreleasepool {book * book = [[Book alloc] init]; [Book setvalue: @ "nbbbbb" forkey: @ "name"]; nsstring * name = [Book valueforkey: @ "name"]; nslog (@ "% @", name );} return 0 ;}