如何使用IOS中的Photos框架在相册中添加图像数组?

时间:2015-11-30 06:31:44

标签: ios frameworks photos

我正在尝试将DKImagePicker集成到我的应用中,因为它看起来更好看。当用户选择相册时,我希望应用程序在我创建的新文件夹中保存用户选择的图像。以下是我试图处理保存的方法:

...

@IBAction func openAlbum(sender: AnyObject) {

  // pickerController is  DKImagePickerController 

  pickerController.didSelectAssets = { [unowned self] (asset: [DKAsset]) in
    print("didSelectAssets")
    self.transferSelectedAssetsToAlbum(asset)
  }
  self.presentViewController(pickerController, animated: true, completion: nil)
}

func transferSelectedAssetsToAlbum(assets: [DKAsset]) {
  PHPhotoLibrary.sharedPhotoLibrary().performChanges({

  // Here I want to save all items in assets in the album
  for asset in assets {
    let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(asset.fullScreenImage!)
    let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset
    let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection)
    albumChangeRequest?.addAssets([assetPlaceholder])
  }

  }, completionHandler: {
    success, error in
    print(success)
    print(error)
  })
} 

...

运行此Xcode时,它抱怨说'NSFastEnumeration' cannot be used with array litteral。我理解这是因为albumChangeRequest?.addAssets([assetPlaholder])不应该在for .. in循环下。但是,我想保存资产中的每个图像?如何在没有for循环的情况下使其工作?

希望我已经说清楚了。如果没有,请告诉我,以便澄清我的问题。

1 个答案:

答案 0 :(得分:0)

显然这个错误具有误导性。对! assetPlaceholder albumChangeRequest?.addAssets([assetPlaceholder]) albumChangeRequest?.addAssets([assetPlaceholder!]) @Path("/StudentService") public class StudentService { @POST @Path("/update") @Consumes(MediaType.APPLICATION_XML) public Response consumeXML( Student student ) { String output = student.toString(); return Response.status(200).entity(output).build(); } } public static void main(String[] args) { try { Student student = new Student(); student.setName("JON"); student.setAddress("Paris"); student.setId(5); String resturl = "http://localhost:8080/RestJerseyClientXML/rest/StudentService/update"; Client client = Client.create(); WebResource webResource = client.resource(resturl); ClientResponse response = webResource.accept("application/xml") .post(ClientResponse.class, student); String output = response.getEntity(String.class); System.out.println("Server response : " + response.getStatus()); System.out.println(); System.out.println(output); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } } catch (Exception e) { } } 。所以我所做的就是用string[] userInputs= { "a","c","b"} DataRow[] datarows=//datarows contains values like "A","B","C","D","E" List<DataRow> data = datarows.CopyToDataTable().AsEnumerable().ToList(); IEnumerable<DataRow> orderedData = data.OrderByDescending(item => Array.IndexOf(userInputs, item.Field<string>(columnName)));

替换private static T CreateValue<T>(ProfileValue profileValue) { // setup code if (typeof(T) == typeof(String)) { // handle strings specially } else if (typeof(T).IsArray) { // handle arrays specially } else if (typeof(T).IsClass) { return Foo.Bar<T>(profileValue.Value); // <-- error occurs here } // additional cases }