简体   繁体   English

如何快速将图像阵列隐藏到任何对象

[英]How to covert an array of images to anyobject with swift

I have an array of images and i want to covert them all to an anyObject object. 我有一个图像数组,我想将它们全部隐藏到anyObject对象中。 How do i do this all at the same time and not one array index at a time? 如何同时执行所有操作,而不一次执行一个数组索引?

Code... 码...

var imageArray:[UIImage] = [Image1, Image2, Image3]

let convertImage:[AnyObject] = UIImagePNGRepresentation(imageArray)
var dataArray:[AnyObject] = [AnyObject]()
for image in imageArray {
    dataArray.append(UIImagePNGRepresentation(image))
}

Or, to steal from @Airspeed Velocity's comment: 或者,从@Airspeed Velocity的评论中窃取:

let dataArray = imageArray.map { UIImagePNGRepresentation($0) as AnyObject }

This has the nice advantage of letting us declare the data array as a let constant rather than a var . 这具有使我们将数据数组声明为let常量而不是var好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM