나는이 소스 코드를 변환하려고 해요에 UnsafeMutableRawPointer의 값을 변환 할 수 없습니다,이 BluetoothDeviceAddress
let deviceAddress: BluetoothDeviceAddress = malloc(sizeof(BluetoothDeviceAddress))
을하지만 발견 스위프트 3/4, sizeof
는 더 이상 사용되지 않지만 내 오류가 아닙니다. Xcode는 다음을 반환합니다.
" 'UnsafeMutableRawPointer!'유형의 값을 변환 할 수 없습니다. 지정된 유형 'BluetoothDeviceAddress' "
malloc(MemoryLayout<BluetoothDeviceAddress>.size)
으로 변경하려고 시도했지만 여전히 동일한 오류가 발생했습니다.
편집 :
self.selectedDevice = IOBluetoothDevice(address: deviceAddress)
: (selectedDevice는 IOBluetoothDevice을위한 VAR입니다) MartinR에 의해 코멘트에서 제안으로 , 나는
let deviceAddress = BluetoothDeviceAddress()
로 변경 시도하지만 내가 IOBluetoothDevice를 초기화 할 때 다음, 나는 여전히 오류가
오류 : 'BluetoothDeviceAddress'유형의 값을 예상되는 인수 유형 'UnsafePointer!'로 변환 할 수 없습니다.
보다도,
앙투안
* 메모리를 할당해야하는 이유는 무엇입니까? 그냥'let/var deviceAddress = BluetoothDeviceAddress()'가 아닌가? –
@MartinR 작동하지 않습니다. 제 편집 참조 – Antoine