2017-03-26 1 views
1

C 라이브러리 - liblinphone과 통합됩니다. 그것은 다음과 같은 typedef와 기능을 가지고 있습니다. Swift 3 iOS app에서 호출해야합니다.Swift 3 CVaListPointer 유형 충돌

typedef void (*OrtpLogFunc)(const char *domain, 
          int lev, 
          const char *fmt, 
          va_list args); 

void linphone_core_set_log_handler(OrtpLogFunc logfunc); 

장치 용으로 컴파일 할 때보다 시뮬레이터에 대해 컴파일 할 때 스위프트 다르게 va_list을 해석하는 것 같습니다. 대상이 때만

class MyClass { 
    func setupLogging() { 
     linphone_core_set_log_handler(my_callback) 
    } 
} 

func my_callback(_ domain: Optional<UnsafePointer<Int8>>, 
    level: OrtpLogLevel, 
    format: Optional<UnsafePointer<Int8>>, 
    args: CVaListPointer?) { // NOTE: Optional CVAListPointer 
     // do some logging 
} 

이 컴파일 : 여기

대상이 장치 때만이 컴파일 C 함수와

사용 스위프트 코드 시뮬레이터 :

class MyClass { 
    func setupLogging() { 
     linphone_core_set_log_handler(my_callback) 
    } 
} 

func my_callback(_ domain: Optional<UnsafePointer<Int8>>, 
    level: OrtpLogLevel, 
    format: Optional<UnsafePointer<Int8>>, 
    args: CVaListPointer) { // NOTE: CVAListPointer is NOT optional 
     // do some logging 
} 

기기에서 실행하면 로깅이 작동하므로 선택 사항 인 CVaListPoint를 사용하고있는 것으로 보입니까?이 가장 안전하므로 시뮬레이터 용으로 컴파일하려면 어떻게해야합니까? 시뮬레이터을 대상으로 할 때 버전은 컴파일

Swift Compiler Error 
    C function pointer signature 
    '(Optional<UnsafePointer<Int8>>, OrtpLogLevel, 
     Optional<UnsafePointer<Int8>>, CVaListPointer?) ->()' 
    is not compatible with expected type 'OrtpLogFunc' (aka 
    '@convention(c) 
    (Optional<UnsafePointer<Int8>>, OrtpLogLevel, 
     Optional<UnsafePointer<Int8>>, CVaListPointer) ->()') 

다음 시뮬레이터을 대상으로 할 때 첫번째 버전은 컴파일하고 장치하지만 문제에서이 컴파일러 오류를 실행

그러나 기기을 타겟팅하면이 오류가 발생합니다.

Swift Compiler Error 
    Cannot convert value of type 
    '(Optional<UnsafePointer<Int8>>, OrtpLogLevel, 
     Optional<UnsafePointer<Int8>>, CVaListPointer) ->()' 
    to expected argument type 'OrtpLogFunc!' 

시뮬레이터가 C 헤더를 변경하지 않고이 기능을 받아들이도록 강제 할 수있는 방법이 있습니까?

또는 스위프트에서이 작업을 수행 할 수있는 방법이 있습니까?

답변

2

가능한 한 빨리 Apple 또는 swift.org으로 버그 보고서를 보내는 것이 좋습니다.

그리고,이 문제는 해결 될 것입니다 때까지 해결 될 코딩 이런 종류의 :이 작동하고

let my_callback: OrtpLogFunc = {domain, level, format, _args in 
    let args: CVaListPointer? = _args 
    // do some logging 
} 
+0

. 고맙습니다! 이제 나머지 오후를 버그 리포트를 작성하는 데 쓰는 중 ... – Troy

관련 문제