NSString *hasancan = @”This is how we create string literally”;
NSNumber * num = @23;
NSArray *arr = @[@”1″,@”2″,@”3″]; // Throws exception if one item is nil. Normal initalization does not throw exception but it only creates items until the nil one.
NSString *first = arr[0];
NSDictionary *dic = @{
@”first”:”hasan”
@”last”:”akgunduz”};
NSString *last = dic[@”last”];
mutableArr[2] = @”cat”;
mutableDic[@”last”] = @”hasan”;
If you create a custom subclass out of NSArray, NSDictionary,NSNumber you can not create them with literal syntax. You can create NSString subclass but it must be changed through compiler option but you will not need that most of the time.
Only immutable ones can be created with literal. To create mutable one:
NSMutableArray *mutArr = [@[@1,@2] mutableCopy]; // an extra object is created but literal syntax easier.
