家庭班中的错误预期声明

时间:2016-11-14 21:49:11

标签: swift xcode

我正在制作一个家庭课,当它弹出一个错误时,它是预期的声明"我不确定它的含义以及如何调试

//
//  ViewController.swift
//  familyClassSecond
//
//  Created by Dordor Zheng on 11/13/16.
//  Copyright © 2016 Dordor Zheng. All rights reserved.
//

import UIKit

class Person {

    var name : String!
    var age : String!
    var idNum : Int!

    init(name:String, age:String, idNum:Int){
        self.name = name
        self.age = age
        self.idNum = idNum

    }

    func sayPerson() -> String{
    let S = "Hi i'm \(name) i am \(age) years old and my id is \(idNum)"
        print(S)
        return S

    }

}

class female : Person {
    var sex : String = "female"
    override func sayPerson() -> String {
        let S = "Hi i'm \(name) and i am \(age) years old"
        print(S)
        return S

    }
}


class male : Person {
    var sex : String = "male"
    override func sayPerson() -> String {
        let S = "Hi i'm \(name) and i am \(age) years old"
        print(S)
        return S

    }
}



class daughter: female {
    var mother : female!
    var father :  male!
    var sibbling : Array<Person>! = []


    init(me:female,father:male,mother:female,brother:male){
        super.init(name: me.name, age: me.age, idNum: me.idNum)
        self.father = father
        self.mother = mother

    }


    override func sayPerson() -> String {
        let S = "I'm \(name), i am \(age) years old my father is \(father.name) and my mother is \(mother.name)"
        print(S)
        return S

    }

    func appendSibbling(brother:Person){
    sibbling.append(brother)

    }



}



class brother: male {
    var mother : female!
    var father :  male!
    var sibbling : Array<Person>! = []


    init(me:male,father:male,mother:female,daughter:female){
        super.init(name: me.name, age: me.age, idNum: me.idNum)
        self.father = father
        self.mother = mother

    }


    override func sayPerson() -> String {
        let S = "I'm \(name), i am \(age) years old my father is \(father.name) and my mother is \(mother.name)"
        print(S)
        return S

    }

}







class father: male {
    var wife : female!
    var children : Array<Person>! = []


    init(me:male, wife:female,child:Person,brother:male){
        super.init(name: me.name, age: me.age, idNum: me.idNum)
        self.wife = wife
        self.children.append(child)
        self.children.append(brother)

    }



    if(children.count == 1 || children.count == 0){
    var choose = "child"
    }else{
    choose = "children"
    }


    override func sayPerson() -> String {
        let S = "I'm \(name), i am \(age) years old i have \(children.count) children and my wife is \(wife.name)"
        print(S)
        return S

    }

}


class mother: female {
    var husband : male!
    var children : Array<Person>! = []


    init(me:female, husband:male,child:Person,brother:male){
        super.init(name: me.name, age: me.age, idNum: me.idNum)
        self.husband = husband
        self.children.append(child)
        self.children.append(brother)

    }


    override func sayPerson() -> String {
        let S = "I'm \(name), i am \(age) years old i have \(children.count) children and my husband is \(husband.name)"
        print(S)
        return S

    }

}



class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let one = female(name: "Dordor", age: "8", idNum: 388313)
        let two = male(name: "Tiger", age: "24", idNum: 773424)
        let three = male(name: "Chiwen", age: "48", idNum: 143303)
        let four = female(name: "Hongwen", age: "47", idNum: 243332)


        let child = daughter(me: one, father: three, mother: four, brother: two)
        let mom = mother(me: four, husband: three, child: one,brother:two)
        let dad = father(me: three, wife: four, child: one,brother: two)
        let bigB = brother(me: two, father: three, mother: four, daughter: one)

        child.sayPerson()
        mom.sayPerson()
        dad.sayPerson()
        bigB.sayPerson()


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

你有任何想法,错误是在if 您可以将粘贴复制到您的代码中,因为我使用的是swift 9.2(它不是测试版)

2 个答案:

答案 0 :(得分:0)

您可以选择两个选项

  • 将选择转换为惰性变量:

    lazy var choose:String = {       if(self.children.count == 1 || self.children.count == 0){          回归“孩子”       } else {          回归“孩子”       }    }()

  • 选择一个功能:

    func choose() - &gt;字符串{       if(self.children.count == 1 || self.children.count == 0){          回归“孩子”       }其他{          回归“孩子”       }    }

答案 1 :(得分:0)

您需要public static void main(String[] args) { try(FileReader fr = new FileReader(new File("C:\\Sample.txt")); CSVReader csvReader = new CSVReader(fr);) { String[] data = csvReader.readNext(); for(String data1 : data) { System.out.println(data1); } } catch (IOException e) { e.printStackTrace(); } } 计算属性:

choose