2016-09-29 17 views
0

私はZipArchive aka SZipArchiveのフォークですが、unzipFileAtPath:toDestination:overwrite:password:progressHandler:completionHandler(phew)機能に問題があります。 WPZipArchive.h#L35-L40(WP/S)ZipArchive進捗/完了ハンドラタイプのSwift

私はスウィフトでのプログラミングだと私は

例えば進捗状況と完了ハンドラのハンドラを書くに問題があります((String!, unz_file_info, Int, Int)->Void)!ハンドラの作成方法は?

いくつかの試み:エラーと

WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: (entry:String!, info:unz_file_info, current:Int, total:Int) { 
    }){ (path:String!, succeeded:Bool, error:NSError!) in 
    } 

.../ViewController.swift:45:142:型の値を変換できません '() - > ()' に期待される引数の型 '(エントリ:文字列!,情報:unz_file_info、 現在:INT、合計:INT)'(別名 '(エントリ: ImplicitlyUnwrappedOptional、情報:unz_file_info_s、現在: のInt、合計:INT)')

この変更は、動作しているようです:)

WPZipArchive.unzipFileAtPath(help, toDestination: temp, progressHandler: {(entry:String!, info:unz_file_info, current:Int, total:Int) in 


    }){ (path:String!, succeeded:Bool, error:NSError!) in 

    } 

答えて

0

私はここに、関数名を参照することはできませんが、2件のハンドラ(閉鎖)進捗ハンドラおよび終了ハンドラがあります。私は1つがあなたが最初に他のパラメータを置くあなたは仕事がハンドラからのデータで使用しようとしている場合、あなたはそれを

foo(completionHandler: { 
    (w:String!, x:unz_file_info, y:Int, z:Int) in 

    print(w) 
    print(x) 
    print(y) 
    print(z) 
}) 

を実装しまた ((String!, unz_file_info, Int, Int)->Void)!

func foo(completionHandler: (String!, unz_file_info, Int, Int)->Void){ 
    //do whatever you need to 
    completionHandler("this is a string", <object of type unz_file_info>, 1, 2) 
} 

を呼び出すかわかりません、閉鎖の詳細については、以下を参照してください https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html

https://thatthinginswift.com/completion-handlers/

関連する問題