2016-09-29 8 views
0

ZipArchive aka SZipArchive의 포크 인 ZIP 라이브러리 WPZipArchive을 사용하려고하는데 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

내가 여기에 함수 이름을 볼 수 없습니다 보이지만 두 개의 핸들러 (폐쇄) 진행 처리기 및 완료 처리기가있다. 나는 하나의 당신이 핸들러에서 데이터로 작업을 사용하려는 경우 대안 ((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) 
} 

당신이 그것을

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

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

먼저 다른 매개 변수를 둘 것입니다 구현하는 것이 호출하는 확실하지 않다 클로저에 대한 자세한 내용은 다음을 참조하십시오 https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html

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