TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Objective-C literals for NSDictionary, NSArray, and NSNumber

102 点作者 julien_p超过 13 年前

13 条评论

Derbasti超过 13 年前
Well, I guess that was long overdue. Anyway, another nice step to bring Objective-C forward.<p>It seems to develop into a nice combination of low-level, high-performance C and a pretty straightforward, dynamic, object system. In short, I vastly prefer its object system to C++, because it reasonably trades some performance for greater dynamisms and an easier syntax.<p>It'll be interesting how Objective-C will develop.
评论 #3610026 未加载
jawngee超过 13 年前
This is for Apple LLVM 4.0 which ships with XCode 4.4.<p>Also included:<p><pre><code> - Automatic @synthesize - NSArray/NSDictionary subscripting, eg id object=MyArray[12];</code></pre>
评论 #3609450 未加载
terhechte超过 13 年前
This is fantastic. Previously I was employing a macro library that offered $dict(k, v, k, v) and $arr(1, 2, 3) and $bool. But the @[] feels much better, and it increases code portability if a class is not dependent upon a separate macro library. It will really remove the verbosity of objc which is oftentimes one of the major criticisms.
boucher超过 13 年前
We've been talking about similar changes to Objective-J for quite some time (we already have JavaScript literals that map more cleanly than C ones). The one thing we've discussed that I don't think made it here is a set literal. It would be nice to have sets treated in a more first class way, considering how often arrays are used when sets would be more appropriate.
评论 #3611449 未加载
cageface超过 13 年前
The excessively verbose collection syntax is my #1 pain point with Obj-C. Looking forward to kicking the tires on this one.
评论 #3609716 未加载
chrisdevereux超过 13 年前
@-prefixed literals for collections are definitely welcome (I won't miss those nested 'dictionaryWith...' calls for sure).<p>Anyone know how the []-access will work? Is this going to be a special case for NSArray/NSDictionary synthesized in by the compiler, or is there going to be runtime support for a []-operator message a la Ruby, or maybe something related to key-value coding?<p>I hope this is done coherently, anyway. I worry that too many special cases to overcome problems like verbose collection access could snowball.
评论 #3609518 未加载
demallien超过 13 年前
ugh. As much as I love the changes that Apple have been making to Objective-C, as someone with a rather large - first-time project undrway, the pace of change is just killing me. In the last three years we have seen blocks (and Grand Central Dispatch) and garbag collection, Automatic Reference Counting, and now this.<p>These are all good changes (well, except for garbage collection, but hey, they kicked that out with ARC anyway), but it really is hard to stay up-to-date. Yeah, I know, woe is me, my tools supplier is constantly supplying better free tools, but it is daunting having to review each of this evolutions, and determine if it is worth the effort to integrate it into my project.
评论 #3609319 未加载
评论 #3609311 未加载
glhaynes超过 13 年前
Nice! As somebody who's not a member of the Mac Developer Program but whose Twitter feed has been <i>full</i> of people gushing about how nice the new additions to Objective-C are, I'm glad to see what all the hubbub is about.
openbear超过 13 年前
I'm glad to see these additions, but the syntax for an NSArray literal bugs me.<p>When I want an array literal in C, I'd write ...<p><pre><code> int foo[] = { 1, 2, 3, 4, 5}; </code></pre> ... but in Objective-C, for an NSArray literal I'd write ...<p><pre><code> NSArray *bar = @[o1, o2, o3]; </code></pre> Why did they choose '[' over '{'? Oddly enough, NSDictionary uses '{'.<p>I feel like the syntax for an NSString literal is more natural (as a C developer).<p><pre><code> NSString *baz = @"look, an NSString literal"; char szBaz[] = "look, a C string literal";</code></pre>
评论 #3610684 未加载
评论 #3610387 未加载
评论 #3610613 未加载
评论 #3610057 未加载
评论 #3610485 未加载
droithomme超过 13 年前
Well this is good news. I have nothing to complain about here, it was even done with the obviously correct syntax following the principle of least surprise. Yay!
natesm超过 13 年前
On one hand, it's nice, and it'll make coding in Obj-C nicer.<p>On the other hand, it strengthens the coupling between Objective-C the language the Cocoa the framework, and I'm not sure how I feel about that.<p>I do like it better than the property dot syntax though. (is a simple assignment to a struct member? is it an objc_msgSend of unknown complexity?)
评论 #3609673 未加载
评论 #3610150 未加载
评论 #3610695 未加载
jemeshsu超过 13 年前
Nice. I wish for ability for function to return multiple values. Is it possible at all?
评论 #3609432 未加载
评论 #3609519 未加载
frou_dh超过 13 年前
Does this come courtesy of a new version of the Objective-C language?<p>The definition of ObjC confuses me a bit. It's said to be a superset of C - but which C? C89? C99? GNU-C-Something?
评论 #3609266 未加载
评论 #3610080 未加载