2016-12-12 10 views
0

Swift 2からSwift 3にコードを移行していますが、コードがこのエラーをスローします。タイプ "className"がプロトコル 'UIDocumentPickerDelegate '私はSwift 3:修正問題タイプ "className"がプロトコル 'UIDocumentPickerDelegate'に準拠していません

extension className: UIDocumentMenuDelegate { 
    //Opening the Document Menu 
    func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) { 
     documentPicker.delegate = self 
     print ("documentMenu") 
     self.present(documentPicker, animated: true, completion: nil) 
    } 

    func documentMenuWasCancelled(_ documentMenu: UIDocumentMenuViewController) { 

    } 
} 
//Using UIDocumentPickerDelegate, error persists here. 
extension className: UIDocumentPickerDelegate { 

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { 
     if(controller.documentPickerMode == UIDocumentPickerMode.import){ 
      print ("success") 
     } 
    } 

} 

class className: BaseViewController{ 

...Tons of code here... 

    @IBAction func importKeyButtonPressed(_ sender: UIButton) { 
    let importMenu = UIDocumentMenuViewController(documentTypes: ["public.data","public.text","public.content"], in: UIDocumentPickerMode.import) 
    var documentPicker = UIDocumentPickerViewController(documentTypes: ["public.txt"], in: UIDocumentPickerMode.import) 
    documentPicker.delegate = self 
    documentPicker.modalPresentationStyle = UIModalPresentationStyle.fullScreen 
    self.present(documentPicker, animated: true, completion: nil) 
} 

がどのように私は私が必要とprocotolすべてのメソッドを使用してきた?それを解決することができ、あなたが見ることができるように私の文書の多くの部分を移行するが、エラー静止画ました。ありがとうございます

+0

私はこの問題についてはわかりませんが、**提案**スウィフトコンベンションに準拠したい場合、クラス名は "className"ではなく "ClassName"である必要があります。 – dfd

+0

問題を再現できません。 'UIDocumentPickerDelegate'に準拠した拡張機能に関するエラーメッセージはありません。問題を再現するのに十分な情報を提供してください。 – OOPer

+0

BaseViewControllerはUIViewControllerから継承していますか? –

答えて

-1

私は同様の問題を抱えているこのリンクの情報を改訂しました。

Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3

問題は自動的にいくつかの情報を認識can'tより迅速コンパイラです。したがって、この場合には:

didPickDocumentAtのURL:URL

それから私は、このリンクに問題をたどる:このリンクで

https://bugs.swift.org/browse/SR-2596

情報は、そのスウィフト3間違いのデータ型であるので、私もう少し調べてこのページにアクセスしてください。この場合の誤ったタイプは「URL」です。

解決策は同じページにあります。私はそれが怒鳴る書く:

weak var delegate : UIDocumentPickerDelegate? 

@available(iOS 8.0, *) 
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: Foundation.URL){ 
    // 
    print("something") 
} 

私は私のコンピュータのエラーを再現している問題に、それはdiferentインポートライブラリが原因で発生しスウィフト3のdoesntは自動的に認識し、この場合のURLのタイプで、データ型の同じ定義を有しますいずれも正しくエラーを通知しません。したがって、直接定義する必要があります。

+0

ありがとう!その答えは私の問題を解決しました。グリーティング –

+0

こんにちはホセ、@엘리ジャベット!このようなことに興味があるならば、スペイン語版のStack Overflowがあることを知らせたいだけです。http://es.stackoverflow.com/ – Shog9

関連する問題