我使用https://stackoverflow.com/a/28964059/6481734处的答案将NSIndexSet转换为[Int]数组我需要做相反的事情,将相同类型的数组转回NSIndexSet。 最佳答案 swift3IndexSet可以使用init(arrayLiteral:)直接从数组文字创建,像这样:letindices:IndexSet=[1,2,3]原始答案(Swift2.2)类似于pbasdf'sanswer,但使用forEach(_:)letarray=[1,2,3,4,5,7,8,10]letindexS