Last active
August 29, 2015 14:03
-
-
Save ejknapp/2a827188ebd6aa3d1212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In C: | |
//============== | |
// The C Function we need to call: | |
// | |
// OSStatus someFunctionForData ( | |
// int *outType, | |
// const void **outData | |
// ) | |
// Will hold the type | |
UInt32 type = 0; | |
// The buffer for our important data | |
const void *data = NULL; | |
// Retrieve the data and its type | |
OSStatus status = someFunctionForData(&type, &data); | |
// Check for the desired type | |
if (type == kRealData_myType) { | |
// Cast the buffer to the struct for use | |
RealDataType *myData = (RealDataType *)data; | |
} | |
//In Swift: | |
//============== | |
// The Swift func we need to call | |
// | |
// func someFunctionForData( | |
// outType: UnsafePointer<Int>, | |
// outData: UnsafePointer<ConstUnsafePointer<()>> | |
// ) -> OSStatus | |
// Will hold the type | |
var type:UInt32 = 0 | |
// The buffer for our important data. | |
// The ConstUnsafePointer is for data we don't know about ahead of time. | |
var data = ConstUnsafePointer<()>() | |
// The status var | |
var status = OSStatus(noErr) | |
// Retrieve the data and its type | |
status = someFunctionForData(&type, &data) | |
// Check for the desired type | |
if type == kRealData_myType { | |
// This is equivalent to the C cast above. It accesses the | |
// raw memory at the pointer address. The var does not need | |
// a specified type due to type inference, but can have one. | |
var myData = UnsafePointer<RealDataType>(data).memory | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist has been updated for Xcode 6 beta 3.