[英]Objective-C equivalent for Smalltalk's at: aKey ifAbsentPut: aBlock?
請考慮以下代碼:
rankedGames at: rank ifAbsentPut: [SortedCollection sortBlock: [:one :two | one name < two name]].
我只看到這種“方便”方法在Smalltalk代碼中使用了幾次,然后就是那里沒有直接的Obj-C等效的SortedCollection。 什么是Objective-C等價物?
什么是Objective-C等價物?
沒有直接的等價物。 NSMutableArray
為您提供了一個可以排序的有序集合,因此可能最接近SortedCollection
。 我不知道at:ifAbsentPut:
的單行等價物,所以你通常會在幾行中做到這一點:
// assume rankedGames is an array of mutable arrays
NSMutableArray *games = rankedGames[rank];
if (games == nil) {
games = [NSMutableArray array];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.