exercism / swift

Exercism exercises in Swift.
https://exercism.org/tracks/swift
MIT License
113 stars 158 forks source link

Windowing System: cannot create a new window #612

Closed CarbonHeartDev closed 1 year ago

CarbonHeartDev commented 1 year ago

If I create and populate the mainWindow instance of Window I get the "expressions are not allowed at the top level" compile error because it seems that Swift doesn't accept expressions outside function and methods unless it's in the main file but if I remove the statements needed to create and configure the new window I get the "cannot find 'mainWindow' in scope" compile error.

I'm stuck and I'm not sure if there's something I don't understood or its a bug in the exercise.

github-actions[bot] commented 1 year ago

Hello. Thanks for opening an issue on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed.

That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link to copy this into a new topic there.


Note: If this issue has been pre-approved, please link back to this issue on the forum thread and a maintainer or staff member will reopen it.

mpbarlow commented 1 year ago

@CarbonHeartDev I just ran into this also. You can get around this by using an immediately-invoked closure, like so:

var mainWindow = {
    var window = Window()

    window.update(title: "Main Window")
    window.update(text: "This is the main window")

    window.resize(to: Size(width: 400, height: 300))
    window.move(to: Position(x: 100, y: 100))

    return window
}()

The test cases themselves use this approach, however I totally agree that this is a something that should be explained in the instructions (or avoided entirely by reworking the tests).

CarbonHeartDev commented 1 year ago

Thanks @mpbarlow and sorry for the late answer. Now I can properly finish the Swift course 😁