1.YES and no
OBJECT-C provides a bool type, but this bool type is not the same as in C + +: everything in C + + that is not 0 value is true, and the value of 0 is false. But Object-c 1 is true and is defined by the macro as yes=1,0 false and defined by the macro as no=0.
+ (BOOL) isequals: (int) x with: (int) y{ return x-y;} if ([Provider isequals:10 with:1021]) {//= = YES//error NSLog (@ "!!!!!!");} else { NSLog (@ "=====");}
2. Class
In a class of OC, it is not allowed to define a function repeatedly, whether the function is repeated according to the method name, regardless of the receive parameter. Different from Java
pubic void GetInfo (Animal a);p ublic void GetInfo (person P);
The same method getinfo:-(void) GetInfo: (Animal) a;-(void) GetInfo: (person) p;
3. Common Collections
void Arraytest () {Nsarray *array = [Nsarray arraywithobjects:@ "one", @ "one", @ "three", nil]; NSLog (@ "len =%lu", [array Count]); For (NSObject *obj in array) {NSLog (@ "= =%@", obj); } for (int i=0; I<[array count]; i++) {NSLog (@ "%@", [array objectatindex:i]); }//write into the file, atomically whether to save the file to a temporary file, after the successful save, and then replace with the original file, is a security mechanism. [Array writetofile:@ "/users/zf/desktop/1.txt" atomically:yes]; Read file Nsarray *arr = [Nsarray arraywithcontentsoffile:@ "/users/zf/desktop/1.txt"]; NSLog (@ "Len3 =%lu", [arr Count]); }
void Mutablearraytest () {Nsmutablearray *array = [Nsmutablearray arraywithcapacity:3]; [Array addobject:@ "one"]; [Array addobject:@ ""]; [Array addobject:@ "three"]; [Array addobject:@ "TWO1"]; NSLog (@ "len =%lu", [array Count]); [Array Removeobjectatindex:3]; NSLog (@ "len =%lu", [array Count]); Nsenumerator *e = [array objectenumerator]; NSString *x; while (x = [E Nextobject]) {NSLog (@ "x = =%@", x); } nsenumerator *e1 = [array reverseobjectenumerator];}
void Dicttest () { nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:@ "value1", @ "Key1", @ "value2", @ " Key2 ", nil]; NSLog (@ "%@", [dict objectforkey:@ "Key2"]); Nsmutabledictionary *d = [Nsmutabledictionary dictionarywithcapacity:3]; [D setobject:@ "wwwwww" forkey:@ "Key1"]; [D removeobjectforkey:@ "Key1"]; NSLog (@ "%lu, key1=%@", [D Count], [D objectforkey:@ "Key1"]);}
Nsarray: An ordered set of elements in an entire block of memory and arranged sequentially;
Nsset: Unordered collection, hash store.
Read Developer.apple's explanation of Nsset: You can use sets as a alternative to arrays when the order of elements isn ' t important and per Formance in testing whether an object was contained in the set is a consideration-while arrays be ordered, testing for MEM Bership is slower than with sets.
Searching for an element, Nsset is more efficient than nsarray. Why is it? The principle is simple: the storage and access of elements in Nsset is a hash process. For example, if you want to store element A, a hash algorithm can directly find the location where a should be stored, and also, when you want to access a, a hash process can find the location of a storage. For Nsarray, if you want to know if a is not in the array, you need an element comparison, obviously inefficient.
4.NSString
void stringtest () {NSString *str = [NSString stringwithformat:@ "AA, BB,CC, "]; Nsarray *array = [str componentsseparatedbystring:@ ","]; NSLog (@ "len =%lu", [array Count]);
NSLog (@ "%@", [Array componentsjoinedbystring:@ "-"]);}