我认为您正在尝试做这样的事情。这只是一个例子。有很多工作要做,但是希望这可以帮助您入门。我没有运行或测试此代码。
想法是将图像另存为
PFFiles,并
PFObject为每个文件创建一个“平铺” 。然后将所有“ tile”保存
PFObject到图像的“
tiles”键中
PFObject。然后在需要时调用图像
objectId。
祝好运。
let appleTiles = ["apple1, apple2, apple3"]let orangeTiles = ["orange1, orange2, orange3, orange4, orange5"]func usage() { //dont literally run these synchronously like this post(appleTiles) post(orangeTiles) download()}func post(_ tileNames: [String]) { let image = PFObject(className: "Image") let tilesPF = tileNames.map({ name in let data = UIImagePNGRepresentation(UIImage(named: name))! let file = PFFile(data: data) let tile = PFObject(className: "Tile") tile["tile"] = file }) image["tiles"] = tilesPF image?.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 })}func download() { let query = PFQuery(className: "image") //add this if you have a specific image you want to get query.whereKey("objectId", equalTo: "someObjectId") query.findObjectsInBackground({ result, error in //this is probably close to how you'd unwrap everything but again, I didn't test it so... if let objects = result as? [PFObject], let first = objects.first, let image = first["image"] as? PFObject, let tiles = image["tiles"] as? [PFObject] { tiles.forEach({ tile in let file = tile["tile"] //now you have an individual PFFile for a tile, do something with it }) } })}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)