• 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 throws from init()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift 2 throws from init()


  • Subject: Swift 2 throws from init()
  • From: Rick Mann <email@hidden>
  • Date: Wed, 01 Jul 2015 16:49:24 -0700

I'm trying to define a Swift wrapper around CGContext. I want to assert that a Context object, if successfully initialized, will always have a valid CGContextRef property. Since at least one of my initializers can fail, I set it up as "throws".

After getting the actual init code to compile, I've run into this: "error: all stored properties of a class instance must be initialized before throwing from an initializer"

I would have thought that if init() throws, there are no guarantees about the state of the object, and thus I would not have to find a way let the CGContext property be optional. It seems the only way to handle this is with an Optional (or implicitly unwrapped Optional) type?

--
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 throws from init()
      • From: Jens Alfke <email@hidden>
    • Re: Swift 2 throws from init()
      • From: Greg Parker <email@hidden>
  • Prev by Date: Re: Swift 2 init() with CF types and throws
  • Next by Date: Re: Swift 2 init() with CF types and throws
  • Previous by thread: Re: Swift 2 init() with CF types and throws
  • Next by thread: Re: Swift 2 throws from init()
  • Index(es):
    • Date
    • Thread