3

I'm trying to create an array within my swift class in Xcode 6 beta 4 but I get the following error:

Swift Compile Error 'Level1.Type' does not have a member named 'someInts'

Here is my code

import SpriteKit

class Level1: SKScene, SKPhysicsContactDelegate {
    var someInts = [Int]()
    var message = "someInts is of type [Int] with \(someInts.count) items."
}

Adding the same variable declarations into a Swift playground does not produce this error.

What am I doing wrong here?

I'm trying to create an array within my class that can hold objects of type Int

Regards

1 Answer 1

3

This issue is with the second variable. You can't assign a property a value that depends on another property inline. You can use a computed property though.

class Level1: SKScene, SKPhysicsContactDelegate {
    var someInts = [Int]()
    var message: String {
        return "someInts is of type [Int] with \(someInts.count) items."
    }
}
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.