• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Swift and UnsafePointer<()>
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Is Swift really swift?
  • Next by Date: Re: Swift Beta 3 has no more CConstPointer
  • Previous by thread: Re: How to delete a autolayout constraint in Xcode 6?
  • Next by thread: Queasy about merging .pbxproj
  • Index(es):
    • Date
    • Thread