• 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 2 init() with CF types and throws
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift 2 init() with CF types and throws


  • Subject: Swift 2 init() with CF types and throws
  • From: Rick Mann <email@hidden>
  • Date: Wed, 01 Jul 2015 16:28:51 -0700

I'm trying to do this:

class
Context
{
    init()
        throws
    {
        let cocoaCTX = NSGraphicsContext.currentContext()
        guard let sysCTX = cocoaCTX.graphicsPort as! CGContextRef else { throw Errors.InvalidContext }
        CGContext = sysCTX;
    }

    var CGContext : CGContextRef
}


But I'm getting

error: value of optional type 'NSGraphicsContext?' not unwrapped; did you mean to use '!' or '?'?
                guard let sysCTX = cocoaCTX.graphicsPort as! CGContextRef else { throw Errors.InvalidContext }
                                   ^
                                           !
In the typical if-let, you don't add the ?. If I do add the ?, I get:

error: '_??' is not convertible to '_??'
                guard let sysCTX = cocoaCTX.graphicsPort? as! CGContextRef else { throw Errors.InvalidContext }
                                   ~~~~~~~~~~~~~~~~~~~~~^

Errors is an enum I created in a different file.

I always seem to trip up on the conditional optional unwrapping. Not sure what I'm doing wrong here. Help is much appreciated. Thanks!

--
Rick Mann
email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Swift 2 init() with CF types and throws
      • From: Marco S Hyman <email@hidden>
    • Re: Swift 2 init() with CF types and throws
      • From: "Stephen J. Butler" <email@hidden>
    • Re: Swift 2 init() with CF types and throws
      • From: Rick Mann <email@hidden>
  • Prev by Date: Re: Swift and parameter names
  • Next by Date: Re: Swift 2 init() with CF types and throws
  • Previous by thread: Re: Problem having a framework working in one of my targets (a screensaver)
  • Next by thread: Re: Swift 2 init() with CF types and throws
  • Index(es):
    • Date
    • Thread