Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does dollar sign mean in objective-c?

 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?

like image 693
水月年华 Avatar asked Jan 17 '11 12:01

水月年华


People also ask

What does the symbol mean in Objective-C?

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.

What does @() mean in Objective-C?

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.


1 Answers

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.

like image 50
zoul Avatar answered Oct 03 '22 13:10

zoul