News for hackers. Stuff that matters.
Re:Is Apple Using Swift? by billconan on Monday January 18, 2016 @02:01PM (#10926140)
here is a case that I have to use !, maybe I'm using it wrong, please correct me.

so I have this "member" in a class

class XXX: UIView

{

   var member: BBB

   init()

   {

      super.init()

      self.member = BBB(self.frame)

   }
}

if I do this, I got the error that self.member is not initialized before super.init

if I move it to before super.init, self.frame isn't available.

my solution to this chicken-egg thing is putting a ? after "member"

Re:Is Apple Using Swift? by cballard on Monday January 18, 2016 @02:38PM (#10926390)

    let member = BBB()

    init()
    {
        super.init()
        member.frame = self.frame
    }
?

Note that since this is a UIView subclass, you're actually implementing init(frame:) and init?(coder:), not init(). I usually unify the two by declaring subviews as lets and initializing them in a private setup method.

Re:Is Apple Using Swift? by stormbrew on Monday January 18, 2016 @04:25PM (#10927078)
While someone replied with a solution to this problem that may work for you, I will say that I do find the rigidity around initializers frustrating.