zl程序教程

您现在的位置是:首页 >  其它

当前栏目

SwiftUI RandomAccessCollection 是什么如何用(2020)

如何 什么 2020 SwiftUI
2023-09-11 14:18:31 时间

SwiftUI RandomAccessCollection 是什么如何用(2020)

得益于Swift的protocol-oriented 设计,因此可以非常容易的实现各种通用算法。

RandomAccessCollection 介绍

A collection that supports efficient random-access index traversal.

支持高效随机访问的集合

RandomAccess集合可以将索引移动到任意距离,并可以在O(1)复杂度时间内从了索引之间的距离。因此随机访问与双向访问之间区别就在于索引移动效率。例如,在O(1)时间内就可以额随机访问count属性,而不需要迭代整个集合。

 
41085-d64ee3e83b73b97b.jpg
RandomAccessCollection 位置

实际应用

RandomAccessCollection 可以应用在List分页项目中,我将在后续教程中进行介绍。

import UIKit

import Foundation
import SwiftUI

extension RandomAccessCollection where Self.Element: I