> On Jul 1, 2015, at 16:51 , Stephen J. Butler <[email protected]> wrote:
> 
> You're focusing on the wrong part :) Which element of your code has a type of 
> "NSGraphicsContext"? It's cocoaCTX! The compiler error is suggesting you do 
> one of these:
> 
> cocoaCTX?.graphicsPort
> cocoaCTX!.graphicsPort

Yeah, I finally figured that out <chagrin>. I keep doing that!

> 
> 
> On Wed, Jul 1, 2015 at 6:28 PM, Rick Mann <[email protected]> wrote:
> 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 protected]
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com
> 
> This email sent to [email protected]
> 


-- 
Rick Mann
[email protected]



_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to