1 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
C.NSStringCGO 生成的與NSStringObjective-C 不兼容。為避免來(lái)自編譯器的警告消息,例如 in const char* nsstring2cstring(),NSString應(yīng)void*在您的 Objective-C 代碼函數(shù)中作為 in 參數(shù)傳遞(foundation.m foundation.h),并將您的void*toNSString和返回為C const char*:
const char* nsstring2cstring(void* s) {
if (s == NULL) { return NULL; }
NSString *cs = *((__unsafe_unretained NSString **)(s));
const char *cstr = [cs UTF8String];
return cstr;
}
在main.goGo 代碼函數(shù)中,它需要C.NSString作為unsafe.Pointerto傳遞nsstring2cstring(void*)
// NSString -> C string
func cstring(s *C.NSString) *C.char { return C.nsstring2cstring(unsafe.Pointer(s)) }
- 1 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報(bào)