0

Let me explain my question with an Example.

class Mother: NSObject {
var momVar:Int =5
var subClass : child(mylevel:5)   //  <-- ********    Error  //
init(){
    momVar=1000
    level=1
}

func print(){
    NSLog("%d",momVar);
}

func subMethod(){
    subClass =child(myVar: 5)  //  <== Doesnt Work either
    yazdir()
}
}

below child class:

class child:Mother{
    var someVar:Int=1
    init(myVar:Int) {
        super.init()
        someVar = myVar
    }

}

I want to use "child" class in "Mother" class. But i got " not initialized at super.init call" error. Other view controller calls "Mother" class with "print" method such as:

@IBAction func buttonTest(sender : AnyObject) {
   var mom=Mother()
   mom.yazdir() 

}

The question is How i can use "child" class in "Mother" class? Thank you

5
  • 2
    what is techTree? I'm not seeing you've defined it... and that line var subClass : techTree(mylevel:5) should be syntactically like var subClass = techTree(mylevel:5) instead. what kind of error did you get anyway at the marked lines of code? Commented Jul 21, 2014 at 20:19
  • In addition to the techTree what is yazdir()? This doesn't compile for me at all as is. Commented Jul 21, 2014 at 20:28
  • techtree=child. I forget to change that:/ now i fix that. Sory for that Commented Jul 21, 2014 at 20:34
  • @holex. Thank you, You are my hero... IF you add your answer i will select you. Thanks again Commented Jul 21, 2014 at 20:37
  • @Antiokhos, I added my comment as an answer. Commented Jul 21, 2014 at 20:51

1 Answer 1

1

this line of code is not correct syntactically as is:

var subClass : child(mylevel:5) 

you need to define the type after the : (before the = if there is any) or you can use it without explicit type, like:

var subClass = child(mylevel:5)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.