CAGradientLayer *grad = [CAGradientLayer layer];
grad.colors = $array(ColRGBA2(1, 0, 0, 1), ColRGBA2(0, 1, 0, 1), ColRGBA2(0, 0, 1, 1), ColRGBA2(0, 0, 0, 0));
grad.startPoint = CGPointMake(0, 0);
grad.endPoint = CGPointMake(1, 0);
grad.colors = $array(ColRGBA2(1, 0, 0, 1), ColRGBA2(0, 1, 0, 1), ColRGBA2(0, 0, 1, 1), ColRGBA2(0, 0, 0, 0));
in this sentence have a dollar sign what does this mean?any links about it?
That symbol is used to declare block. For more information read here Blocks Programming Topics. Some more info: Block objects are a C-level syntactic and runtime feature.
It's Shorthand writing. In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals.
That’s not a feature of the language, these are convenience intializers for collections that some people use. For example:
$array(foo, bar, baz)
expands to:
[NSArray arrayWithObjects:foo, bar, baz, nil]
I’m not sure if it’s worth the trouble. And I don’t have a link to the library that provides these macros, maybe somebody else does?
By the way, it looks like we will have official literals for arrays, dictionaries and some other objects in Xcode 4.4. The details appear to be under NDA at the moment, but there’s some discussion at Hacker News.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With