Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Compiler wrongly interprets the expected argument type of a swift Function?

I am learning and trying to write a board in swift in IOS to play weiqi/baduk. I implement the board by spritekit. I create a new class named BoardNode as below. However, I have an error when compiled. Error Message: "Cannot convert value of type 'CGSize' to expected argument type 'BoardNode'". The error is at the line when I call the function createGridquare() in the class fun of boardAtPosition. The expected argument of my written function should be CGSize. However, the compiler said that it should be BoardNode. I don't know why. Please help.

==========================================

class BoardNode: SKSpriteNode {
    class func boardAtPosition(position: CGPoint, size: CGSize) -> SKSpriteNode {

        let board = BoardNode(color: SKColor.whiteColor(), size: size)
        ........................................
        shiftx = 1
        shifty = 1
        let boardWidth = size.width
        let boardHeight = size.height
        let gridSquareWidth = boardWidth/20
        let gridSqaureHeight = boardHeight/20
        while (shifty <= 18) {
            while (shiftx <= 18) {
                let test: SKShapeNode = createGridSquare(CGSizeMake(gridSquareWidth, gridSqaureHeight))
                gridSquare.position = CGPointMake(gridSquareWidth*0.5+gridSquareWidth*CGFloat(shiftx), gridSqaureHeight*0.5+gridSqaureHeight*CGFloat(shifty))
                board.addChild(gridSquare)
                shiftx = shiftx + 1
            }
            shiftx = 1
            shifty = shifty + 1
        }

        return board
    }

    func createGridSquare(size: CGSize) -> SKShapeNode {
        let gridSquare = SKShapeNode(rectOfSize: size)
        gridSquare.zPosition = 1
        gridSquare.fillColor = SKColor.clearColor()
        gridSquare.lineWidth = 1
        gridSquare.strokeColor = SKColor.blackColor()

        return gridSquare
    }