Search code examples
objective-ccocoaxcode4.5xcode4.4

Annotation of @[object] for NSArray


I happend to see one particular code,

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

What's the name of annotation @[indexPath], I never see this kind. and since when it introduces in objective-C. I know it replaces [NSArray arrayWithObjects:indexPath,nil], any other functions of that? what the feature to use this (well, other than shorter)?

Thanks.


Solution

  • That is an extension to the "Literals" available in Objective-C with LLVM. I don't believe it does anything else apart from create an array. They became available with Apple LLVM 4.0.

    If you'd like to see all the literals available, check out http://clang.llvm.org/docs/ObjectiveCLiterals.html - they're quite handy.