Swift 2 throws from init()
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