看板 MacDev 關於我們 聯絡資訊
最近突然發現的, 好像還沒人提過, 不知道大家知不知道, 分享一下 從 llvm-gcc-4.0 和 clang-3.1 開始, Objective-C 增加了新的 literal 寫法 大家都知道 NSString 可以用 @"some text" 產生 literal 現在這個東西也可以用在其他 Foundation 資料型別上 NSNumber *fortyTwo = @42; NSArray *fooBar = @[@"foo", @"bar"]; NSDictionary *someDict = @{@"key0": @"value0", @"key1": @"value1"}; 然後相對的, 現在 NSArray 和 NSDictionary 更可以用 subscript 運算子 NSString *value0 = someDict[@"key0"]; NSString *foo = fooBar[0]; 這樣以後就不會只為了產生一些簡單的資訊, 就必須寫一堆落落長的東西了 更多資訊可以參看 Clang 網站的說明 http://clang.llvm.org/docs/ObjectiveCLiterals.html Xcode 的 refactor 功能裡面也有可以自動轉換現有程式碼的工具 Edit -> Refactor -> Convert to Modern Objective-C Syntax -- Les grandes et les meilleurs tone from "Zadok the Priest" Eine grosse stattliche Veranstaltung by F. Handel THE MAIN EVENT! These are the men Sie sind die Besten "Champions League" by Tony Britten THESE ARE THE CHAMPIONS! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.81.146
dreambird:是說,這個從哪一版的xcode開始支援啊,4.5? 10/27 23:33
uranusjr:我也不確定, 不過應該是在那之前一點, 可能 4.4 吧 10/27 23:47
uranusjr:只要檢查 compiler 版本有到就是有了 10/27 23:49
scentsome:llvm 4.0 以上,要有Xcode 4.4以上http://bit.ly/RpMVLu 10/28 09:59