我正在尝试获取从图书馆导入的图像的URL,以便使用 transferFile(_:metadata)
将其发送到Apple Watch ,但是在NSURL
上出现了两个错误。
这是我的代码:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!)
{
imagePicked.image = image
let imageUrl = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL
let imageName = imageUrl.path!.lastPathComponent
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as String!
let localPath = documentDirectory.stringByAppendingPathComponent(imageName)
let image = editingInfo[UIImagePickerControllerOriginalImage]as! UIImage
let data = UIImagePNGRepresentation(image)
data!.writeToFile(localPath, atomically: true)
let photoURL = NSURL(fileURLWithPath: localPath)
self.dismissViewControllerAnimated(true, completion: nil);
}
我使用*imageName和*localPath时出现错误,提示如下:
'lastPathComponent'不可用:请改用NSURL的lastPathComponent。 'stringByAppendingPathComponent'不可用:请改用NSURL的URLByAppendingPathComponent。
但是我在Swift 2.0和Xcode 7中无法正确实现。我错在哪里了?