[swift-users] Problems - hard to describe

Joe Groff jgroff at apple.com
Fri Jun 24 17:42:08 CDT 2016


> On Jun 24, 2016, at 12:17 PM, Kenny Leung via swift-users <swift-users at swift.org> wrote:
> 
> Hi All.
> 
> I fixed my Problems. It turns out I had the declaration typed wrong. CType should have been CChar instead of [CChar]. The working version is this:
> 
> public struct ArrayBridge<SwiftType,CType> {
> 
>     let originals  :[SwiftType]
>     let translated :[[CType]]
>     let pointers   :[UnsafePointer<CType>?]
>     public let pointer    :UnsafePointer<UnsafePointer<CType>?>
> 
>     init(array :[SwiftType], transform: @noescape (SwiftType) throws -> [CType]) throws {
>         self.originals = array
>         self.translated = try array.map(transform)
> 
>         var pointers = [UnsafePointer<CType>?]()
>         for item in translated {
>             pointers.append(UnsafePointer<CType>(item))
>         }
>         pointers.append(nil)
> 
>         self.pointers = pointers
>         self.pointer = UnsafePointer(self.pointers)
>     }
> }

Glad to hear you were able to work your problem out. If you have time, we'd still appreciate a bug report about the unhelpful type error message.

-Joe


More information about the swift-users mailing list