Hallo dort stackoverflowers. Ich implementiere einen Wrapper für Secure Transport und ich bleibe bei einigen der C -> Swift-Syntax stecken.Kopieren Sie NSData in UnsafeMutablePointer <Void>
func sslReadCallback(connection: SSLConnectionRef,
data: UnsafeMutablePointer<Void>,
var dataLength: UnsafeMutablePointer<Int>) -> OSStatus
{
//let bytesRequested = dataLength.memory
let transportWrapper:SecureTransportWrapper = UnsafePointer(connection).memory
let bytesRead:NSData = transportWrapper.readFromConnectionFunc(transportWrapper.connection)
dataLength = UnsafeMutablePointer<Int>.alloc(1)
dataLength.initialize(bytesRead.length)
if (bytesRead.length == 0)
{
return OSStatus(errSSLClosedGraceful)
}
else
{
data.alloc(sizeof(bytesRead.length)) //<----compile error here
return noErr
}
}
Ich habe den Speicherort der Kompilierfehler markiert. Ich beschuldige es nicht für Irrtum, ich habe hier raten: P. Ich versuche, die NSData in die Daten zu kopieren: UnsafeMutablePointer. Wie mache ich das?
Compile Fehler:
/Users/*/SecureTransportWrapper.swift:108:9: Static member 'alloc' cannot be used on instance of type 'UnsafeMutablePointer' (aka 'UnsafeMutablePointer<()>')
Dank einer Tonne!
================
Update: hier ist die api doc für das, was die sslReadCallback tun soll: here
connection: A connection reference.
data: On return, your callback should overwrite the memory at this location with the data read from the connection.
dataLength: On input, a pointer to an integer representing the length of the data in bytes. On return, your callback should overwrite that integer with the number of bytes actually transferred.
Auszug aus
OK, also alle gut dann. Oder haben Sie irgendwelche zusätzlichen Probleme? – hnh
Nein, solange Ihre Antworten den Dokumenten entsprechen! Vielen Dank - ich werde deine als richtig markieren. –