Swift 1.2 to swift 2: Objective C 方法与可选需求方法冲突
Swift 1.2 to swift 2: Objective C method conflicts with optional requirement method
我正在尝试根据我在网上找到的教程 (https://www.raywenderlich.com/85528/user-accounts-ios-ruby-rails-swift#next_section) 开发一个访问 phone 相机的应用程序。然而,我在 imagePickerController 函数中的相机扩展不断抛出这个错误:
Objective-C method 'imagePickerController: didFinishPickingMediaWithInfo:
' provided by method 'imagePickerController(_:didFinishPickingMediaWithInfo:)
' conflicts with optional requirement method imagePickerController(_:didFinishPickingMediaWithInfo:)
这是抛出错误的代码
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {}
受影响的代码块如下图
// Camera Extension
extension SelfieCollectionViewController : UINavigationControllerDelegate, UIImagePickerControllerDelegate {
func displayCameraControl() {
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front) {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Front
} else {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Rear
}
} else {
imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
}
self.presentViewController(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
}
}
可以在此处 (https://codeshare.io/UurWD) 第 111 行找到完整的代码块。
替换
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { }
和
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { }
我正在尝试根据我在网上找到的教程 (https://www.raywenderlich.com/85528/user-accounts-ios-ruby-rails-swift#next_section) 开发一个访问 phone 相机的应用程序。然而,我在 imagePickerController 函数中的相机扩展不断抛出这个错误:
Objective-C method '
imagePickerController: didFinishPickingMediaWithInfo:
' provided by method 'imagePickerController(_:didFinishPickingMediaWithInfo:)
' conflicts with optional requirement methodimagePickerController(_:didFinishPickingMediaWithInfo:)
这是抛出错误的代码
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {}
受影响的代码块如下图
// Camera Extension
extension SelfieCollectionViewController : UINavigationControllerDelegate, UIImagePickerControllerDelegate {
func displayCameraControl() {
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front) {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Front
} else {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Rear
}
} else {
imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
}
self.presentViewController(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
}
}
可以在此处 (https://codeshare.io/UurWD) 第 111 行找到完整的代码块。
替换
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { }
和
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { }