Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create an array within a class in Xcode using Swift

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

like image 515
ripe Avatar asked May 22 '26 06:05

ripe


1 Answers

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."
    }
}
like image 53
Mick MacCallum Avatar answered May 23 '26 20:05

Mick MacCallum