[英]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.