Apple has changed something in its NSString and NSURL in its latest version (iOS 9), but these methods are available from iOS 4. You can check the related Apple Forum Post for more details.
To fix this error you need to change the code as follows:
Swift 2:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { let imageUrl = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL let imageName = imageUrl.lastPathComponent let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as String! let photoURL = NSURL(fileURLWithPath: documentDirectory) let localPath = photoURL.URLByAppendingPathComponent(imageName!) let image = editingInfo[UIImagePickerControllerOriginalImage]as! UIImage let data = UIImagePNGRepresentation(image) data!.writeToFile(localPath.absoluteString, atomically: true) self.dismissViewControllerAnimated(true, completion: nil); }
Swift 3:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { let imageUrl = info[UIImagePickerControllerReferenceURL] as! NSURL let imageName = imageUrl.lastPathComponent let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! let photoURL = NSURL(fileURLWithPath: documentDirectory) let localPath = photoURL.appendingPathComponent(imageName!) let image = info[UIImagePickerControllerOriginalImage]as! UIImage let data = UIImagePNGRepresentation(image) do { try data?.write(to: localPath!, options: Data.WritingOptions.atomic) } catch {
Link:
source share