Post

Replies

Boosts

Views

Activity

Reply to Type conversion issue from 'UnsafeMutableRawPointer' to UnsafeMutablePointer<Int32>
Thanks for help. Actually I am trying to port following 'test' API from C++ to Swift. Here, following 'test' function calls sysctl with void type data in 'request' pointer and sysctl returns the result with same 'request' pointer with int type data. But i am facing issues with below two lines to port from C++ to Swift.  int *ret = (int *)request;  return *ret; C++ function: int test(test_type type, void *request, size_t request_len) {   size_t size = request_len;  int mib[] = {0,0,0,0,0};       if (0 == sysctl(mib, 5, request, &amp;size, NULL, 0)) {     int *ret = (int *)request;     return *ret;   } else if (errno == EISDIR || errno == ENOENT) {     return 0;   }   return -1; } Swift function: func test( type: test_type, request: UnsafeMutableRawPointer, request_len: size_t) -> Int32 {   var size: Int = request_len   var mib: [Int32] = [0, 0, 0, 0, 0]   let val: Int32 = sysctl(&amp;mib, 5, request, &amp;size, nil, 0)   if (val == 0) {     let ret = request     return UnsafeMutableIPointer&lt;Int32&gt;ret   } else if (errno == EISDIR || errno == ENOENT) {     return 0   }   return -1 }
Aug ’20