Objective-C中的Swift地图和flatmap?

时间:2017-04-27 16:00:41

标签: objective-c swift

Swift有函数map和flatmap。在Objective-C中有任何等价物吗?我一直试图将Apple的Photos示例部分翻译成我自己的Objective-C代码。使用它的特定代码如下:

fileprivate func updateCachedAssets() {
    // Update only if the view is visible.
    guard isViewLoaded && view.window != nil else { return }

    // The preheat window is twice the height of the visible rect.
    let visibleRect = CGRect(origin: collectionView!.contentOffset, size: collectionView!.bounds.size)
    let preheatRect = visibleRect.insetBy(dx: 0, dy: -0.5 * visibleRect.height)

    // Update only if the visible area is significantly different from the last preheated area.
    let delta = abs(preheatRect.midY - previousPreheatRect.midY)
    guard delta > view.bounds.height / 3 else { return }

    // Compute the assets to start caching and to stop caching.
    let (addedRects, removedRects) = differencesBetweenRects(previousPreheatRect, preheatRect)
    let addedAssets = addedRects
        .flatMap { rect in collectionView!.indexPathsForElements(in: rect) }
        .map { indexPath in fetchResult.object(at: indexPath.item) }
    let removedAssets = removedRects
        .flatMap { rect in collectionView!.indexPathsForElements(in: rect) }
        .map { indexPath in fetchResult.object(at: indexPath.item) }

    // Update the assets the PHCachingImageManager is caching.
    imageManager.startCachingImages(for: addedAssets,
        targetSize: thumbnailSize, contentMode: .aspectFill, options: nil)
    imageManager.stopCachingImages(for: removedAssets,
        targetSize: thumbnailSize, contentMode: .aspectFill, options: nil)

    // Store the preheat rect to compare against in the future.
    previousPreheatRect = preheatRect
}

我已设法翻译例程indexPathsForElementsIn:rect。我只是不太了解地图和平面图功能,以生成相当的东西。

0 个答案:

没有答案