Swift and UnsafePointer<()>
Swift and UnsafePointer<()>
- Subject: Swift and UnsafePointer<()>
- From: Marco S Hyman <email@hidden>
- Date: Wed, 09 Jul 2014 14:13:02 -0700
This code seems to work on a mac in beta3
extension NSGraphicsContext {
var cgcontext: CGContext! {
if let graphicsPort = NSGraphicsContext.currentContext()?.graphicsPort() {
let opaqueContext = COpaquePointer(graphicsPort)
return Unmanaged<CGContext>.fromOpaque(opaqueContext).takeUnretainedValue()
}
return nil
}
}
It is also a lot of work for what (I think) is mainly making
the type safety aspects of the compiler happy. However, pretty much
everything else I've tried resulted in either compiler errors or
bad results. My first try:
let foo = UnsafePointer<CGContext>(NSGraphicsContext.currentContext().graphicsPort()).memory
does not give me a value that CGContextDrawImage likes.
In beta2 the return type of graphicsPort() was a COpaquePointer
which simplified the code a bit... I didn't need to convert the
UnsafePointer<()> to a COppaquePointer, first.
Someone please tell me I'm doing this the hard way. I'm not getting
a lot of help from the documentation. I'd like to understand what
is going on.
Marc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden