将UnsafeMutablePointer转换为[String:AnyObject]

时间:2015-11-17 16:16:21

标签: swift pointers dictionary casting

我已将[String:AnyObject]作为userdata传递给addToolTipRect ..

var myObject = [String:AnyObject]()

self.addToolTipRect( binCoordinates, owner: self, userData: &myObject )

因此,在stringForToolTip中,我需要将其转换回[String:AnyObject]

var theData = [String:AnyObject](data)不起作用。

1 个答案:

答案 0 :(得分:0)

// userData: UnsafeMutablePointer<Void>

let pUserData = UnsafeMutablePointer<Dictionary<String,AnyObject>>(userData)

// you can accsees all properties and functions via

pUserData.memory.myPropery // read or write myObject.myProperty
pUserData.memory.foo()     // execute myObject.foo()