[swift-users] IUO from C Library Interface

Ryan Lovelett swift-dev at ryan.lovelett.me
Mon Oct 24 16:24:42 CDT 2016


import CommonCrypto

protocol Foo {
  associatedtype Context
  var context: Context { get set }
  var bar: (UnsafeMutablePointer<Context>!, UnsafeRawPointer!, CC_LONG)
  -> Int32 { get }
}

struct SHA1: Foo {
  var context: CC_SHA1_CTX
  var bar: (UnsafeMutablePointer<CC_SHA1_CTX>!, UnsafeRawPointer!,
  CC_LONG) -> Int32 = CC_SHA1_Update
}

Unfortunately this will not compile any longer with Swift 3.0. The error
is: Implicitly unwrapped optionals are only allowed at top level and as
function results.

I can try modifying `bar` definition to be `?` instead of `!` but then
`CC_SHA1_Update`) can no longer be assigned to `bar`.

Suggestions?


More information about the swift-users mailing list