strnmn
strnmn

Reputation: 565

Cast UnsafeMutablePointer<Void> to my struct type

In my swift code I use the peertalk objective-c library using a bridging-header.

In a delegate method I get some payload in a parameter with the type of UnsafeMutablePointer<Void>.

How can I cast the payload to my struct type in Swift so I can use the data?

Upvotes: 1

Views: 1291

Answers (1)

joels
joels

Reputation: 7741

Just a guess referencing from here

struct YourStruct {
    var name : String
}
var structInstance = YourStruct.init(name: "Jose")

func delegateMethod(voidPtr : UnsafePointer<Void>) {
    //CONVERSION HERE
    let myStruct = UnsafePointer<YourStruct>(voidPtr).memory
    print("\(myStruct.name)")
}
delegateMethod(&structInstance)

Upvotes: 3

Related Questions