Starting with xcode4.4, the LLVM4.0 compiler adds some new features to Objective-c. Creating an array nsarray, a hash table nsdictionary, and a numeric object NSNumber can be as simple and convenient as the initialization of a nsstring. Mother is no longer worried about the process of writing is sour.
Interested friends can focus on LLVM compiler related documentation: http://clang.llvm.org/docs/ObjectiveCLiterals.html
Examples of nsdictionary and nsnumber from: http://cocoaheads.tumblr.com/post/17757846453/objective-c- Literals-for-nsdictionary-nsarray-and
I. Nsarray
The first is the very common nsarray,nsmutablearray. Nsarray is a static array that is initialized and fixed. If you want to insert, delete, update, and so on the elements of an array, you must use the OBJECTIVE-C dynamic array Nsmutablearray.
Before LLVM4.0, the Nsarray initialization method is as follows. Note: The following methods can continue to be used after LLVM4.0.
Initialization of Nsarray before LLVM4.0
Nsarray *oldone = [Nsarray arraywithobjects:@ "1st", @ "2nd", @ "3th", nil];
Gets the 2nd value of the array
NSString *s = [Oldone objectatindex:1];
After LLVM4.0, the Nsarray initialization method is as follows.
Nsarray *newone =@[@ "1st", @ "2nd", @ "3th"];
Gets the 2nd value of the array
NSString *s = newone[1];
Especially to say Nsmutablearray. Before LLVM4.0, if you want to update an element of an array, you typically use the following method.
Initialization of Nsmutablearray before LLVM4.0
Nsmutablearray *oldmutable = [Nsmutablearray arraywitharray:old];
[mutable replaceobjectatindex:1 withobject:@ "disposed"]; Update an element
When writing some common algorithms, the following features cause a bit of trouble writing.
/* Want to update an element of Nsmutablearray? Please initialize this element first * *
Nsmutablearray *oldmutable = [[Nsmutablearray alloc] init]];
/* Must assign an initial value to each element as follows, otherwise exception will occur
for (int h = 0; h < 5; h++) {
[Oldmutable addobject:@ "1"];
}
@try {
[mutable replaceobjectatindex:1 withobject:@ "disposed"];
}
@catch (NSException *exception) {
NSLog (@ "%@", [exception description]);
}
This LLVM4.0 simplifies this process and can be done in the following way.
After LLVM4.0
Nsmutablearray *newmutable = [Nsmutablearray alloc] init];
NEWMUTABLE[2] = @ "MyObject";