[swift-users] Updating C-wrapper to Swift 3

Quinn "The Eskimo!" eskimo1 at apple.com
Thu Sep 29 03:42:23 CDT 2016


On 28 Sep 2016, at 18:39, Michael Ilseman <milseman at apple.com> wrote:

> Could you share the generated interface for these functions, so that we can see how they are being imported into Swift?

Based on some random expat docs I found on the ’net [1], I grabbed the relevant declarations and put them in a bridging header.

---------------------------------------------------------------------------
typedef struct XML_Parser_struct * XML_Parser;
typedef uint8_t XML_Char;

typedef void
(*XML_EndElementHandler)(void *userData,
                         const XML_Char *name);

void XML_SetEndElementHandler(XML_Parser p,
                         XML_EndElementHandler);
---------------------------------------------------------------------------

With that I see that XML_EndElementHandler has the signature:

typealias XML_EndElementHandler = (UnsafeMutableRawPointer?, UnsafePointer<XML_Char>?) -> Void

However, John is trying to use:

{ (userData: UnsafeMutableRawPointer, name: UnsafePointer<XML_Char>) -> Void in … }

where the parameters differ in optionality.  The fix is to make both parameters optional:

{ (userData: UnsafeMutableRawPointer?, name: UnsafePointer<XML_Char>?) in … }

I belive this change is the result of:

* SE-0055 “Make unsafe pointer nullability explicit using Optional”

<https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md>

* SE-0054 “Abolish ImplicitlyUnwrappedOptional type”

<https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md>

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

[1] <http://www.hpc.wm.edu/SciClone/documentation/software/misc/expat/reference.html>



More information about the swift-users mailing list