First, Cgpoint defines a point, and two parameters are X, Y, respectively
1>cgpoint p = {100,100};
2>cgpoint p;
p.x = 100;
P.Y = 100;
3>cgpoint p = cgpointmake (100,100);
Second, cgsize defines a size: two parameters are width, height
Three, CGRect defines a rectangle: Four parameters are origin.x, ORIGIN.Y, Size.width, Size.Height
Iv. Nsrange defines a range: Two parameters are: location, length
Five, static string NSString assignment statement:
1>nsstring * str = [NSString stringwithformat:@ "%d", 123];
2>nsstring * str = [NSString stringwithstring:@ "abc"];
3>nsstring * str = [[NSString alloc]initwithformat:@ "%d", 123];
4>nsstring * str = [NSString stringwithutf8string: "abc"];
Six, 1> all the strings into uppercase: str = [str uppercasestring];
2> all lowercase: str = [STR lowercasestring]
Seven: To find the string length:1> using [str lengthofbytesusingencoding:nsutf8stringencoding], the Chinese character length is 3;
2> when using [str length], the Chinese character length is 1;
Determine if there is a string in the string: Use Nsrrange range = [str rangeofstring:@ "AB"]; Then use the IF statement to Judge Range.location==nsnotfound to execute
Ix. Comparison of string contents: Using the If statement to determine [STR isequaltostring:@ "ABC"] to perform
Ten, the string is converted to a numeric value: int a = [str integervalue];//double a = [str doublevalue];
Xi. determine whether to start with what string: bool b = [str hasprefix:@ "A"];//end use [str hassuffix]
12. Extract substring:1> starting from somewhere: [str substringfromindex:2];//starting from 0, including the location
2> extracted to a location: [str substringtoindex:3];//starting from 0, excluding the location
3> extracts the middle of a few characters: Nsrange range = {n}; [STR substringwithrange:range];//can use this function to implement the reverse output of a string
13. Remove the spaces at both ends of the string: [str stringbytrimmingcharrctersinset:[nscharacterset whitespacecharacterset]];
14. Add a string after the string: [str stringbyappendingstring:@ "ABC"]
XV, modify the contents in the string: Nsrange R ={0,1}; [Str replacecharactersinrange:r withstring:@ "abc"];
16. Delete the content in the string: [str deletecharactersinrange:r];
17. Add content to the string: nsmutablestring * str = [nsmutablestring stringwithcapacity:100]; [String appendformat:@ "123"];
18. Write string to file: [str writetofile:@ "Abc.txt" Automically:no encoding:nsutf8stringencoding Error:nil];
19, static array of three methods of assignment:
1>nsarray * array = @[@ "1", @ "2", @ "3"];//Direct Assignment
2>nsarray * array = [Nsarray arraywithobjects:@ "1", @ "2", @ "3", nil];
3>nsarray * array = [[Nsarray alloc]initwithobjects:@ "1", @ "2", @ "3", nil];
Two methods of traversal:
1> loop traversal for (int i=0;i<[array count];i++)
2> Fast Traversal for (NSString * str in array)
20. Dynamic array: Nsmutablearray *arr = [Nsmutablearray arraywithcapacity:20]
1> Add object: [arr addobject:[nsstring stringwithformat:@ "123"];
2> Delete object: [Arr removeobject:@ "2"];
3> Insert Object: [arr insertobject:@ "abc" atindex:0];
21, the contents of the collection can not be repeated:
Nsset * set = [Nsset setwithobject:@ "1", @ "2", @ "3", @ "2", nil];
Nsarray * arr = [set allobjects];
arr = [arr sortedarrayusingselector: @selector (compare:)];
22. Dynamic Collection:
Nsmutableset * set = [Nsmutableset setwithcapacity:20];
23. Static and Dynamic dictionary
Nsdictionary * Dict = [[Nsdictionary alloc] initwithobjectsandkeys:@ "Zhang San", @ "1", @ "John Doe", @ "2", Nil];//value,key
Nsmutabledictionary * Dict = [[Nsmutabledictionary alloc]initwithcapacity:20];
[Dict setobject:@ "Zhangsan" forkey:@ "1"];//add
[Dict setobject:@ "Lisi" forkey:@ "2"];
[Dict setobject:@ "Wangwu" forkey:@ "1"];
[Dict removeobjectforkey:@ "2"];//Delete
Nsarray * keys = [dict AllKeys];
For (NSString *str in keys)
{
NSLog (@ "key=%@,value=%@", Str,[dict Objectforkey:str]);
}
24, the array can only store object type, so before storing the first to use Nsvalue,nsnumber into object type
Cgpoint p1 = {100,100};
Nsvalue * v = [Nsvalue valuewithpoint:p1];
Nsarray *arr = [Nsarray Arraywithobjects:v,nil]
25, NSData:
Nsarray * array = [[Nsarray alloc]initwithobjects:@ "1111", @ "2222", @ "3333", @ "4444", nil];
Nsarray *array = [Nsarray arraywithcontentsoffile:@ "Array.plist"];//array writetofile: @ "array.plist" Atomically:NO]; Write to file, Nsset, nsdictionary
NSData * data = [NSData datawithcontentsoffile:@ "a.jpg"];//read out a.jpg file
[Data writetofile:@ "b.jpg" atomically:yes];//addressed to B.jpg file. Equivalent to copy function
iOS learning the next day (data types commonly used in OC)