因此,出于演示目的,我从我的 xcassets 中访问了一组图像。我试图使用解析框架一次将 150 张图像保存到我的解析服务器。这是我到目前为止的代码。我遇到的问题是我的应用程序 cpu 在测试中达到 100% 并下降到 0。图像也没有保存以进行解析。我希望有人可以帮助我找到一种有效的方法来保存 150 张图像进行解析。
var imageNameList: [String] {
var imageNameList2:[String] = [] //[NSMutableArray]()
for i in 0...149 {
let imageName = String(format: "pic_%03d", Int(i))
imageNameList2.append(imageName)
}
return imageNameList2
}
@IBAction func Continue(_ sender: Any) {
for imageName in imageNameList {
var objectForSave:PFObject = PFObject(className: "Clo")
let object:UIImage = UIImage(named: imageName)!
let tilesPF = imageNameList.map({ name in
let data = UIImagePNGRepresentation(object as! UIImage)!
let file = PFFile(data: data)
let tile = PFObject(className: "Tile")
tile["tile"] = file
})
objectForSave["tiles"] = tilesPF
objectForSave.saveInBackground(block: { responseObject, error in
//you'll want to save the object ID of the PFObject if you want to retrieve a specific image later
})
}
}