0
var allCards = [CCard]
var cardsMade = 0

^^ is outside of my view controller class as to make it global and accessible in all other view controller files.

in another view controller i have

@IBAction func saveInfo(sender: UIButton) {
    let a = CCreature(n: cName!, e: cExpansion, ec: cEnergy!, tc: cTurnCount!,
        ef: cEffect!, at: cStrength!, ht:cHealth!, sp: cSpeed!, sb: false)
    allCards.append(a)
    cardsMade++}

so when the saveInfo button is pressed, i put all the information the user has typed (which were in UITextFields, and then saved into the corresponding vairables cEnergy etc..) into a subclass of CCard called CCreature, with all of the information. After I create the instance of the class, i am trying to store in the array allCards. I am getting an error on the line:

var allCards = [CCard]

Expected member name or constructor call after type name

And in the line where a is appended to the array i am getting this error:

Cannot convert value of type 'CCreature' to expected argument type 'inout Array < CCard >'

I was also getting this error message before, when my program was compiling:

fatal error: Array index out of range

Any ideas?

1 Answer 1

1

As you have it [CCard] is a type declaration, you could use it as:

var allCards : [CCard]

but, that won't actually initialize allCards to be useful, alternatively, you could actually create the array and initialize it using:

var allCards = [CCard]()

Where you're using the default array constructor

It's not the entirety of your example, because you didn't include a lot of the pieces, but stripped down to show usage, would be:

var allCards = [CCard]()

func saveInfo() {
    let a = CCreature()
    allCards.append(a)
}
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.