[英]Objective-C equivalent for Smalltalk's at: aKey ifAbsentPut: aBlock?
Consider the following code: 请考虑以下代码:
rankedGames at: rank ifAbsentPut: [SortedCollection sortBlock: [:one :two | one name < two name]].
I've only seen this "convenience" method used a couple of times in Smalltalk code, and then there is that SortedCollection there with no direct Obj-C equivalent. 我只看到这种“方便”方法在Smalltalk代码中使用了几次,然后就是那里没有直接的Obj-C等效的SortedCollection。 What is the Objective-C equivalent?
什么是Objective-C等价物?
What is the Objective-C equivalent?
什么是Objective-C等价物?
There isn't a direct equivalent. 没有直接的等价物。
NSMutableArray
gives you an ordered collection that can be sorted, so that's probably the closest to SortedCollection
. NSMutableArray
为您提供了一个可以排序的有序集合,因此可能最接近SortedCollection
。 I don't know of a single-line equivalent of at:ifAbsentPut:
, so you'd normally do that in a few lines: 我不知道
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.